Last active
June 19, 2016 16:14
-
-
Save greymd/75f9c9f5cf528ed2c84f1d2e4d073a26 to your computer and use it in GitHub Desktop.
分割数を求める際の整数の分割方法を表示したい
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
#!/usr/bin/env egison | |
(define $main | |
(lambda [$args] | |
(each display (divnum (read (car args)))))) | |
(define $divnum | |
(lambda [$n] | |
(unique | |
(match-all (take n (repeat1 1)) (list integer) | |
[(loop $i [1 n] <join $a_i ...> <nil>) | |
[(sort (map 1#a_%1 (between 1 n)))]])))) | |
; 5を分割する例 | |
; $ egison partition_num_detail.egi 5 | |
; {0 0 0 0 5} | |
; {0 0 0 1 4} | |
; {0 0 0 2 3} | |
; {0 0 1 1 3} | |
; {0 0 1 2 2} | |
; {0 1 1 1 2} | |
; {1 1 1 1 1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment