Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greymd/fb45abc82971eec318d6 to your computer and use it in GitHub Desktop.
Save greymd/fb45abc82971eec318d6 to your computer and use it in GitHub Desktop.
任意の自然数の体積を持つ直方体の持ち得る自然数x, y, zの組み合わせを求めるEgisonシェル芸
$ echo 64 | \
egison -T -m '1#(match-all (p-f %1) (multiset integer) [ <join $xs <join $ys $zs>> [(foldl * 1 xs) (foldl * 1 ys) (foldl * 1 zs)]])' | \
xargs -n 3 | \
egison -T -f '3#(and (lte? %1 %2) (lte? %2 %3))' | \
sort | uniq
# 結果 (体積64の直方体)
# 1 1 64
# 1 2 32
# 1 4 16
# 1 8 8
# 2 2 16
# 2 4 8
# 4 4 4
@egisatoshi
Copy link

!/bin/sh

echo 64 |
egison -T -s '1#(match-all (p-f (car %1)) (multiset integer) [ <join $xs <join $ys $zs>> [(foldl * 1 xs) (foldl * 1 ys) (foldl * 1 zs)]])' |
egison -T -F1c -f '1#(all lte? (match-all %1 (list integer) [ <join _ <cons $x <cons $y _>>> [x y]]))' |
sort | uniq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment