18 lines
597 B
Text
18 lines
597 B
Text
F s_permutations(seq)
|
||
V items = [[Int]()]
|
||
L(j) seq
|
||
[[Int]] new_items
|
||
L(item) items
|
||
I L.index % 2
|
||
new_items [+]= (0..item.len).map(i -> @item[0 .< i] [+] [@j] [+] @item[i..])
|
||
E
|
||
new_items [+]= (item.len..0).step(-1).map(i -> @item[0 .< i] [+] [@j] [+] @item[i..])
|
||
items = new_items
|
||
|
||
R enumerate(items).map((i, item) -> (item, I i % 2 {-1} E 1))
|
||
|
||
L(n) (3, 4)
|
||
print(‘Permutations and sign of #. items’.format(n))
|
||
L(perm, sgn) s_permutations(Array(0 .< n))
|
||
print(‘Perm: #. Sign: #2’.format(perm, sgn))
|
||
print()
|