def total_number_sequence(m, n):
if m < n:
return 0
if n == 0:
return 1
res = (total_number_sequence(m - 1, n) +
total_number_sequence(m // 2, n - 1))
return res
if __name__ == '__main__':
m = 10
n = 100
print('Total number of possible sequences:', total_number_sequence(m, n))
PROBLEM: 3N+1 sequence: determine which value(s) of N generate the longest sequence for the famous 3N+1 sequence. Refer to 8.5 in your runestone text for more details. Output the value(s) of N that generate the longest sequence.
C version: use 100 as the value of N
Consider the following to help you better understand how to solve this problem.
OUTPUT FORMAT:
C version - a single number
What is wrong with my code?
The first condition is always true, since m < n. Therefore, the function will always return 0.
In addition, as I understand it, you are trying to use recursion into lines with a variable res. Well, you need to understand that calling the first function recursively will not make it possible to call the second one, since the function will constantly start doing everything from the beginning.
Comments
Leave a comment