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

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

时间:2015-08-21 09:23:31      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/bhlsheji/p/4746802.html

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