Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,21 @@
include c:\cxpl\codes;
func Prisoner(N, K); \Return final surviving prisoner
int N, K; \number of prisoners, number to skip
int I, J;
char A;
[A:= Reserve(N);
for I:= 0 to N-1 do A(I):= I;
I:= 0;
repeat I:= I+K-1; \skip to next prisoner
I:= rem(I/N); \wrap to start if necessary
IntOut(0, A(I)); ChOut(0, ^ ); \show killed prisoner
for J:= I to N-2 do A(J):= A(J+1); \shift survivors down
N:= N-1; \one less prisoner
until N=1;
return A(0);
];
[IntOut(0, Prisoner(5, 2)); CrLf(0);
IntOut(0, Prisoner(41, 3)); CrLf(0);
]