Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active June 19, 2016 16:14
Show Gist options
  • Save greymd/75f9c9f5cf528ed2c84f1d2e4d073a26 to your computer and use it in GitHub Desktop.
Save greymd/75f9c9f5cf528ed2c84f1d2e4d073a26 to your computer and use it in GitHub Desktop.
分割数を求める際の整数の分割方法を表示したい
#!/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