Permutations by swapping: Difference between revisions

Line 2,941:
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ stack ] is parity ( --> s )
 
[ 1 & ] is odd ( n --> b )
 
[ dup[] 0swap = iffwitheach
[ drop ' [ [ ] ] ]
done
dup temp put
1 - recurse
[] swap
witheach
[ i odd parity put
temp share times
[ temp share 1 -
over
parity share
iff i else i^
stuff
nested rot join
swap ]
drop
parity release ]
temp release ] is perms ( n --> [ )
 
[ dup 0 peek
size odd parity put
[] swap witheach
[ nested
parityi shareodd 2 * 1 -
parity release ]join nested join ] ] is +signs ( [ --> [ )
iff i^ else i
odd 2 * 1 -
join
nested join ]
parity release ] is +signs ( [ --> [ )
 
[ dup 0 peek
3 perms +signs
witheach [ echodup 0 cr= ]iff
[ drop ' [ [ ] ] ]
done
dup temp put
1 - recurse
[] swap
witheach
[ i odd parity put
temp share times
[ temp share 1 -
over
parity share
iff i else i^
stuff
nested rot join
swap ]
drop
parity release ]
nestedtemp joinrelease ]
swap odd if reverse
temp release+signs ] is perms ( n --> [ )
 
3 perms witheach [ echo cr ]</syntaxhighlight>
cr
4 perms +signswitheach [ echo cr ]</syntaxhighlight>
witheach [ echo cr ]</syntaxhighlight>
 
{{out}}
 
<pre>[ [ 1 0 1 2 ] -1 ]
[ [ 1 2 0 ] 1 ]
[ [ 2 1 0 ] -1 ]
[ [ 2 0 1 ] 1 ]
[ [ 0 2 1 ] -1 ]
[ [ 2 0 1 2 ] 1 ]
[ [ 2 1 0 ] -1 ]
[ [ 1 2 0 ] 1 ]
[ [ 1 odd0 2 *] -1 -]
 
[ [ 0 1 2 3 ] 1 ]
1,483

edits