Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Challenge 74 [E]

By: a guest on Jul 11th, 2012  |  syntax: Ruby  |  size: 0.34 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def zeck(n)
  2.         arr = Array.new
  3.         temp = 0
  4.         n.times do |x|
  5.                 fibo = fib(x)
  6.                 arr << fibo if fibo <= n && fibo != 0
  7.                 temp = x if fibo <= n
  8.                 break if fibo > n
  9.         end
  10.         arr << fib(temp+1)
  11.         arr = arr.reverse
  12.         ans = Array.new
  13.         while n > 0
  14.                 arr.each do |x|
  15.                         if x <= n && x != 0
  16.                                 ans << x
  17.                                 n = n-x
  18.                         end
  19.                 end
  20.         end
  21.         puts ans
  22. end