码迷,mamicode.com
首页 > 其他好文 > 详细

projecteuler---->problem=34----Digit factorials

时间:2014-08-25 11:59:14      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:ruby   projecteuler   

Problem 34

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

Find the sum of all numbers which are equal to the sum of the factorial of their digits.

Note: as 1! = 1 and 2! = 2 are not sums they are not included.


puts (0..50000).select{|i|
    i.to_s.length>1 && i == i.to_s.each_char.map{|d| (1..d.to_i).reduce(1,:*)}.reduce(:+)}.reduce(:+)


projecteuler---->problem=34----Digit factorials

标签:ruby   projecteuler   

原文地址:http://blog.csdn.net/q745401990/article/details/38816975

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!