Created
July 22, 2012 10:32
-
-
Save keroxp/3159198 to your computer and use it in GitHub Desktop.
プログラミングコンテストの問題
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
#ダメ解答 | |
f = 1 | |
s = 0 | |
for i in 1..100 do | |
f *= i | |
end | |
n = f | |
for i in 0..Math.log10(f).floor do | |
n,b = n.divmod(10) | |
s+= b | |
end | |
puts s |
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
#模範解答 | |
f = 1 | |
fs = "" | |
s = 0 | |
for i in 1..100 do | |
f *= i | |
end | |
fs = f.to_s | |
for i in 0 .. fs.length - 1 do | |
s += fs[i,1].to_i | |
end | |
puts s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment