Josephus problem: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) REXX added |
Walterpachl (talk | contribs) →{{header|REXX}}: generalized + extended |
||
Line 146:
=={{header|REXX}}==
<lang rexx>/* REXX
* 15.11.2012 Walter Pachl - my own solution
* 16.11.2012 Walter Pachl generalized n prisoners + w killing distance
* and s=number of survivors
**********************************************************************/
dead.=0 /* nobody's dead yet */
n=41 /* number of alive prisoners */
nn=n /* wrap around boundary */
w=3 /* killing count */
s=1 /* nuber of survivors */
p=-1 /* start here */
killed='' /* output of killings */
Do until n=
found=0 /* start looking */
Do Until found=
p=p+1 /* next position */
If p=
If dead.p=0 Then /* a prisoner who is alive */
found=found+1 /* increment found count */
Line 167 ⟶ 172:
Say 'killed:'subword(killed,1,20) /* output killing sequence */
Say ' 'subword(killed,21) /* output killing sequence */
Do
End</lang>
▲Say 'Prisoner' i 'survives' /* show */</lang>
Output:
<pre>
Line 176 ⟶ 181:
31 36 40 6 12 19 25 33 39 7 16 28 37 10 24 1 21 3 34 15
Prisoner 30 survives
</pre>
=={{header|Scala}}==
|