Hofstadter's Q sequence
"""Hofstadter's Q-Sequence is a sequence of numbers where every integer above zero has a corresponding q-sequence value. You can determine the q-sequence value from a formula that tells you how far back in the sequence to go and add two values together. The first two values of the sequence are Q(1) = 1 and Q(2) = 1, and every number above 2 can be expressed according to the following formula (n is your input): Q(n) = Q(n - Q(n - 1)) + Q(n - Q(n -2)) Task: Given an integer value input, determine and output the corresponding q-sequence value.""" a = int(input()) def hof(n): if n <=1: return 1 elif n ==2: return 1 elif n==3: return 2 elif n==4: return 3 elif n==5: return 3 else : return hof(n - hof(n - 1)) + hof(n - hof(n - 2)) print(hof(a)) # To this question, the code lines above do not produce the expected result. I am not sure where it went wrong. if anyone would help me I would appreciate it. Thanks in advance!