Josephus problem: Difference between revisions

Added Arturo implementation
(Added Arturo implementation)
Line 891:
Program End ok.
</pre>
 
=={{header|Arturo}}==
 
<lang rebol>josephus: function [n,k][
p: new 0..n-1
i: 0
seq: []
 
while [0 < size p][
i: (i+k-1) % size p
append 'seq p \ i
remove 'p .index i
]
print ["Prisoner killing order:" chop seq]
print ["Survivor:" last seq]
print ""
]
 
print "josephus 5 2 =>"
josephus 5 2
 
print "josephus 41 3 =>"
josephus 41 3</lang>
 
{{out}}
 
<pre>josephus 5 2 =>
Prisoner killing order: [1 3 0 4]
Survivor: 2
 
josephus 41 3 =>
Prisoner killing order: [1 3 0 4 2 2 5 8 11 14 17 20 23 26 29 32 35 38 0 4 9 13 18 22 27 31 36 40 6 12 19 25 33 39 7 16 28 37 10 24 1 21 3 34 15]
Survivor: 30</pre>
 
=={{header|AutoHotkey}}==
<lang AHK>; Since AutoHotkey is 1-based, we're numbering prisoners 1-41.
1,532

edits