fork download
  1. def fib_gen(max):
  2. a, b = 1, 1
  3. yield 1
  4. while a < max:
  5. yield a
  6. a, b = a + b, a
  7.  
  8.  
  9. def zeck_representation(num):
  10. gen_array = list(fib_gen(num))
  11. find_num = num
  12. zeck_array = []
  13. while find_num > 0:
  14. zeck_array.append(gen_array[-1])
  15. find_num -= gen_array[-1]
  16. for i in range(0, len(gen_array) - 1):
  17. if gen_array[i] > find_num:
  18. gen_array = gen_array[:i]
  19. break
  20. output = str(num) + ' = '
  21. zeck_array = ' + '.join(str(i) for i in zeck_array)
  22. output += zeck_array
  23. return output
  24.  
  25. challenge = [4, 100, 30, 5, 120 , 34, 88, 90, 320]
  26. for i in challenge:
  27. print(zeck_representation(i))
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
4 = 3 + 1
100 = 89 + 8 + 3
30 = 21 + 8 + 1
5 = 3 + 3
120 = 89 + 21 + 8 + 2
34 = 21 + 21
88 = 55 + 21 + 8 + 3 + 1
90 = 89 + 1
320 = 233 + 55 + 21 + 8 + 3