Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Last active August 29, 2015 13:57
Show Gist options
  • Save zakuroishikuro/9858662 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/9858662 to your computer and use it in GitHub Desktop.
フィボナッチ数列
def fibonacci(num)
[1,1].tap{|a|(num-2).times{a<<a[-2,2].inject(:+)}}[0,num]
end
#p fibonacci 10 #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment