Permutations by swapping: Difference between revisions
Added Quackery.
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Added Quackery.) |
||
Line 2,938:
{{out|Sample output}}
The output is the same as before and is a list of all results rather than yielding each result from a generator function.
=={{header|Quackery}}==
<syntaxhighlight lang="Quackery"> [ stack ] is parity ( --> s )
[ 1 & ] is odd ( n --> b )
[ dup 0 = 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 ]
temp release ] is perms ( n --> [ )
[ [] swap witheach
[ nested
i^ odd 2 * 1 -
join
nested join ] ] is +signs ( [ --> [ )
3 perms +signs
witheach [ echo cr ]
cr
4 perms +signs
witheach [ echo cr ]</syntaxhighlight>
{{out}}
<pre>[ [ 1 0 2 ] -1 ]
[ [ 1 2 0 ] 1 ]
[ [ 2 1 0 ] -1 ]
[ [ 2 0 1 ] 1 ]
[ [ 0 2 1 ] -1 ]
[ [ 0 1 2 ] 1 ]
[ [ 0 1 2 3 ] -1 ]
[ [ 0 1 3 2 ] 1 ]
[ [ 0 3 1 2 ] -1 ]
[ [ 3 0 1 2 ] 1 ]
[ [ 3 0 2 1 ] -1 ]
[ [ 0 3 2 1 ] 1 ]
[ [ 0 2 3 1 ] -1 ]
[ [ 0 2 1 3 ] 1 ]
[ [ 2 0 1 3 ] -1 ]
[ [ 2 0 3 1 ] 1 ]
[ [ 2 3 0 1 ] -1 ]
[ [ 3 2 0 1 ] 1 ]
[ [ 3 2 1 0 ] -1 ]
[ [ 2 3 1 0 ] 1 ]
[ [ 2 1 3 0 ] -1 ]
[ [ 2 1 0 3 ] 1 ]
[ [ 1 2 0 3 ] -1 ]
[ [ 1 2 3 0 ] 1 ]
[ [ 1 3 2 0 ] -1 ]
[ [ 3 1 2 0 ] 1 ]
[ [ 3 1 0 2 ] -1 ]
[ [ 1 3 0 2 ] 1 ]
[ [ 1 0 3 2 ] -1 ]
[ [ 1 0 2 3 ] 1 ]
</pre>
=={{header|Racket}}==
|