the number of trailing zeros in a factorial of a given number - Ruby
问题 Having a little trouble trying calculate the number of trailing zeros in a factorial of a given number. This is one of the challenges from Codewars- can't get mine to pass. zeros(12) = 2 #=> 1 * 2 * 3 .. 12 = 479001600 I think I'm on the wrong path here and there is probably a more elegant ruby way. This is what I have down so far. def zeros(n) x = (1..n).reduce(:*).to_s.scan(/[^0]/) return 0 if x == [] return x[-1].length if x != [] end 回答1: This is more of a math question. And you're right,