Created
July 10, 2012 12:23
-
-
Save taiki45/3082967 to your computer and use it in GitHub Desktop.
s = 1, 3, ... 99 をすべて足す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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