1234567891011121314151617181920 |
- #!/usr/bin/ruby
- # Daniel "Trizen" Șuteu
- # License: GPLv3
- # https://github.com/trizen
- # Find the sum of all numbers which are equal to the sum of the factorial of their digits.
- # https://projecteuler.net/problem=34
- # Runtime: 1.636s (previously: 2.673s)
- var f = (0..9 -> map {|d| d! })
- var sum = (3..1e5 `by` 2 -> grep { |n|
- n.digits.sum_by { f[_] } == n
- }.sum)
- say sum
|