13 lines
352 B
Plaintext
13 lines
352 B
Plaintext
10 LET n=41: LET k=3: LET m=0
|
|
20 GO SUB 100
|
|
30 PRINT "n= ";n;TAB (7);"k= ";k;TAB (13);"final survivor= ";lm
|
|
40 STOP
|
|
100 REM Josephus
|
|
110 REM Return m-th on the reversed kill list; m=0 is final survivor.
|
|
120 LET lm=m: REM Local copy of m
|
|
130 FOR a=m+1 TO n
|
|
140 LET lm=FN m(lm+k,a)
|
|
150 NEXT a
|
|
160 RETURN
|
|
200 DEF FN m(x,y)=x-INT (x/y)*y: REM MOD function
|