Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
21
Task/Josephus-problem/XPL0/josephus-problem.xpl0
Normal file
21
Task/Josephus-problem/XPL0/josephus-problem.xpl0
Normal 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);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue