HACKER RANK Project Euler 34 - Digit Factorials - Solution.'Rb'

Project Euler Challenges-34 - Digit Factorials Solution
Problem Statement
This problem is a programming version of Problem 34 from projecteuler.net
19 is a curious number, as 1!+9!=1+362880=362881 which is divisible by 19.
Find the sum of all numbers below N which divide the sum of the factorial of their digits.
Note: as 1!,2!,,9! are not sums they are not included.
Input Format 
Input contains an integer N
Output Format 
Print the answer corresponding to the test case.
Constraints 
10N105
Sample Input
20
Sample Output
19

Solution:


p (11..gets.to_i-1).select{|i|i.to_s.chars.map{|e|(2..e.to_i).reduce(1,:*)}.reduce(:+)%i==0}.reduce(0,:+)

Thanks for Visiting, Hope this helps you....



Comments

Popular Posts