Skip to content

Instantly share code, notes, and snippets.

@taiki45
Created July 10, 2012 12:23
Show Gist options
  • Save taiki45/3082967 to your computer and use it in GitHub Desktop.
Save taiki45/3082967 to your computer and use it in GitHub Desktop.
s = 1, 3, ... 99 をすべて足す
# without for
Array.new(50) {|n| 2 * n + 1}.inject(:+)
# with for
s = 0
for i in (0..49) do
s = s + lambda{|n| 2 * n + 1}.call(i)
end
s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment