fork download
  1. def zeckendorf_that_number(n):
  2. a, b, total, check, f_list, r_list = 1, 1, 0, True, [], []
  3. while b <= n:
  4. f_list.append(b)
  5. a = a + b
  6. b = a - b
  7. f_list.reverse()
  8. for i in f_list:
  9. if i + total <= n and check:
  10. total, check = total + i, False
  11. r_list.append(i)
  12. elif not check:
  13. check = True
  14. return list(map(str, r_list))
  15.  
  16. challenge_input = list(map(int, '5\n120\n34\n88\n90\n320'.splitlines()[1:]))
  17. for i in challenge_input:
  18. print(str(i) + ' = ' + ' + '.join(zeckendorf_that_number(i)))
Success #stdin #stdout 0s 9992KB
stdin
Standard input is empty
stdout
120 = 89 + 21 + 8 + 2
34 = 34
88 = 55 + 21 + 8 + 3 + 1
90 = 89 + 1
320 = 233 + 55 + 21 + 8 + 3