Hackerrank – Problem description
The problem description Hackerrank.
Solution
The catch is to have a support for big numbers operations in your progamming language.
Do a factorial and sum the numbers.
I created solution in:
All solutions are also available on my GitHub profile.
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
def factorial(n) fact = 1 for i in 2..n do fact *= i end return fact end def sum_digits(number) chars = number.to_s.chars sum = 0 chars.each { |char| sum += char.to_i } return sum end gets.chomp.to_i.times do n = gets.chomp.to_i puts sum_digits(factorial(n)) end |