Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active January 1, 2016 05:25
Show Gist options
  • Save greymd/53ff6a5c33c11177ac47 to your computer and use it in GitHub Desktop.
Save greymd/53ff6a5c33c11177ac47 to your computer and use it in GitHub Desktop.
1,2,3の3つの数字を並び替えた時の全パターンを列挙する
$ echo {1,2,3}{1,2,3}{1,2,3}'\n' | awk '$1=$1' | sed -nr '/(.)(.?)\1/!p'
123
132
213
231
312
321
$ echo 1 2 3 | egison -F1,1c -T -m '(match-all-lambda (multiset integer)[<cons $a <cons $b <cons $c _>>> [a b c "#_EOF_#"]])' | sed -r 's/\t"#_EOF_#"\t?/\n/g' | awk -F '\t' '$1=$1'
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
# こんなコマンドがあったらなぁ
$ echo 1 2 3 | egison-sed -m '<cons $a <cons $b <cons $c _>>>' 'a b c'
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment