Last active
May 19, 2016 16:19
-
-
Save greymd/7d81faa38cf1141ad0a923a841531eb2 to your computer and use it in GitHub Desktop.
Egisonでソウルナンバー (https://twitter.com/twi_carnival/status/732782289604612096) を計算する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; num-to-digits from egison-libs https://github.com/egison-libs/project-euler | |
(define $num-to-digits | |
(lambda [$n] | |
(map 1#(read (pack {%1})) (unpack (show n))))) | |
(define $soul-sum | |
1#(match (num-to-digits %1) (list integer) | |
{[<cons $s ,{}> s] | |
[<cons $a $b> (soul-sum (foldl + a b))]})) | |
(define $main | |
(lambda [$args] | |
(display | |
(soul-sum (read (car args)))))) | |
; 実行例 | |
; $ egison soul-number.egi 20111201 | |
; > 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment