I did notice a few related questions to this problem (I also did a little research of this problem on the web). However, all of them are iterative; I am a little baffled on how this problem can be solved using recursion:
def is_buyable(n):
''' return whether amount n McNuggets is buyable at McDonalds (using 6, 9 and 20 packs) '''
if n == 0:
return True
#...
#insert some code or if statement, with call on is_buyable(n)
else:
return False
As you noticed, this method returns a Boolean. Any help would be appreciated!
Recursion works by breaking down each problem to a “smaller” version of the same problem. In this case, you can insert this code: