:ClLCD
:Input "Number in circle?",N
:Input "Remove every?",K
:N→dimL S //
S will hold all the original objects.
:For(I,1,N) //
The objects are initialized in the form of a complex number
:(I,0)→S(I) //
where the real part is the number and the imaginary part is the
:End
// condition: dead or alive.
:1→I //
I counts the number of objects (living or dead) encountered in all.
:1→M //
M is the number of objects encountered.
:0→D //
D is the number of objects killed so far.
:While (D<N-1)
If ((mod(M,K)==0) and (imag S(1+mod(I-1,N))==0))
// If your time is up and you're still alive . . .
: Then
: (1+mod(I-1,N),1)→S(1+mod(I-1,N))
// Bye, bye - you're removed.
: D+1→D
// Increase the number of dead.
: I+1→I
// Increase the number of living or
dead encountered.
: M+1→M
// Increase the number of living encountered.
:For(J,0,N-1)
:Outpt(1+mod(J,8),1,S(J+1))
:If (((mod(J+1,8)==0)
or (mod(J+1,N)==0))) // This code is
optional - it will print
:Then
// out the players, living and dead
:Pause
:End
:End
: End
// If a living object is encountered whose number is not up
: If (imag S(1+mod(I-1,N))==0)
: Then
: M+1→M //
Increase the number of living encountered.
: End
// End "if" of "alive and number's
up" condition
: I+1→I
// In any case, increase the number of living or dead encountered.
:End //
End while
:0→J
:Repeat (imag (S(J))==0) //
Find the number of the survivor
: J+1→J
:End
:Outpt(4,7,"The number of")
:Outpt(5,7,"the survivor ")
:Outpt(6,7,"is")
:Outpt(6,10,real (S(J))
:ClLCD
:Outpt(3,1,"Enter the number, N,"
:Outpt(4,1,"of starters"
:Outpt(5,1,"The number,K,to omit."
:Outpt(6,1,"& the I-th eliminated"
:Prompt N,K,I
:I*Küx
:While (x>N)
:iPart ((K*(x-N)-1)/(K-1))üx
:End
:Outpt(7,1,"The"
:Outpt(7,5,I)
:Outpt(7,6+iPart (log (I)),"-th one out is"
:Outpt(8,1,x)
Download a uuEncoded QE2