Josephus problem: Difference between revisions

Content deleted Content added
added Quackery
→‎{{header|Quackery}}: added variable number of survivors
Line 3,360: Line 3,360:
Not the fastest method, but illustrates use of ancillary stacks, and using nests as queues.
Not the fastest method, but illustrates use of ancillary stacks, and using nests as queues.


<lang Quackery>[ stack ] is prisoners ( --> s )
<lang Quackery>[ stack ] is survivors ( --> s )


[ stack ] is executioner-actions ( --> s )
[ stack ] is prisoners ( --> s )

[ stack ] is executioner-actions ( --> s )


[ [] swap times [ i^ join ]
[ [] swap times [ i^ join ]
prisoners put ] is make-prisoners ( n --> )
prisoners put ] is make-prisoners ( n --> )


[ prisoners take
[ prisoners take
behead join
behead join
prisoners put ] is walk ( --> )
prisoners put ] is walk ( --> )


[ prisoners take
[ prisoners take
behead drop
behead drop
prisoners put ] is kill ( --> )
prisoners put ] is kill ( --> )


[ [] swap 1 - times
[ [] swap 1 - times
[ ' walk nested join ]
[ ' walk nested join ]
' kill nested join
' kill nested join
executioner-actions put ] is make-executioner ( n --> )
executioner-actions put ] is make-executioner ( n --> )


[ executioner-actions take
[ executioner-actions take
behead dup do nested join
behead dup do nested join
executioner-actions put ] is execute-kth ( --> )
executioner-actions put ] is execute-kth ( --> )


[ survivors put
[ make-executioner
make-executioner
make-prisoners
make-prisoners
[ execute-kth
[ execute-kth
prisoners share
prisoners share
size 1 = until ]
size
survivors share = until ]
survivors release
executioner-actions release
executioner-actions release
prisoners take 0 peek ] is josephus ( n n --> n )</lang>
prisoners take ] is josephus ( n n n --> n )</lang>


'''Testing in Quackery shell:'''
'''Testing in Quackery shell:'''


<pre>/O> 41 3 josephus
<pre>/O> 41 3 1 josephus
... 41 3 3 josephus
...
...


Stack: 30</pre>
Stack: [ 30 ] [ 15 30 34 ]</pre>


=={{header|R}}==
=={{header|R}}==