Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4 (40 points] Dr. Vink of the Math Lab has made a conjecture about a particular sequence of numbers that he calls the Vink

image text in transcribed

Question 4 (40 points] Dr. Vink of the Math Lab has made a conjecture about a particular sequence of numbers that he calls the Vink sequence. He claims that for any odd integer k > 0, a sequence of numbers can be constructed as follows. Start with an integer n > 0. Then, the next term in the sequence is if n is even, or 3n + k if n is odd. Vink claims that this sequence will eventually produce a term of 1 after some number of terms. For example, starting with n = 9 and k = 1, we get the sequence 9, 28, 14, 7, 22, 11, 34, 17,52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, which reaches 1 after 20 terms. To help check Vink's claim, we will write code that checks how many terms it takes to converge to 1 with given values of n and k. You must write a function vink_sequence(n, k, j) that computes the first j terms of the Vink sequence for the given values of n and k. If none of the j terms are 1, then the function should return -1. If you do encounter a term of 1, then the function should stop computing terms and immediately return the number of terms that have been computed so far. For example, if the 37th term of the sequence is 1, then the function should immediately return the value 37. Next, outside your function, ask the user to type in a value for n, k and j. If either n 0, k >= 0 and 3 > 0. (You can assume the user will always enter numbers, without any letters/symbols, etc.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

How would a check sheet be used in a modern production facility?

Answered: 1 week ago

Question

=+ How could you make it more engaging and entertaining?

Answered: 1 week ago