Skip to content

Instantly share code, notes, and snippets.

@keroxp
Created July 22, 2012 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keroxp/3159198 to your computer and use it in GitHub Desktop.
Save keroxp/3159198 to your computer and use it in GitHub Desktop.
プログラミングコンテストの問題
#ダメ解答
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
#模範解答
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