Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.31 KB | None | 0 0
  1.  
  2. n=gets.to_i
  3. d=[]
  4. d[0]=0
  5. o="0 "
  6. if n>1
  7.     d[1]=1
  8.     o+="1 "
  9.     n.times do|x|
  10.         if x>1
  11.             d[x]=d[x-1]+d[x-2]
  12.             o+=d[x].to_s+' '
  13.         end
  14.     end
  15. end
  16. puts o[0..-2]
  17.  
  18. # for golf
  19. n=gets.to_i;d=[];d[0]=0;o="0 ";if n>1;d[1]=1;o+="1 ";n.times do|x|;if x>1;d[x]=d[x-1]+d[x-2];o+=d[x].to_s+' ';end;end;end;puts o[0..-2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement