Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
53
Task/Josephus-problem/ERRE/josephus-problem.erre
Normal file
53
Task/Josephus-problem/ERRE/josephus-problem.erre
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
PROGRAM JOSEPHUS
|
||||
|
||||
!
|
||||
! for rosettacode.org
|
||||
!
|
||||
|
||||
!$INTEGER
|
||||
|
||||
DIM DEAD[100]
|
||||
|
||||
PROCEDURE MAIN(N,K,S->ERRORS)
|
||||
! n - number of prisoners
|
||||
! k - kill every k'th prisoner
|
||||
! s - number of survivors
|
||||
LOCAL KILLED$,SURVIVED$,FOUND,P,NN,I
|
||||
ERRORS=0
|
||||
FOR I=0 TO 100 DO
|
||||
DEAD[I]=0
|
||||
END FOR ! prepare array
|
||||
PRINT("N=";N,"K=";K,"S=";S) ! show arguments
|
||||
IF S>N THEN PRINT("S>N";) ERRORS+=1 END IF
|
||||
IF K<=0 THEN PRINT("K<=0";) ERRORS+=1 END IF
|
||||
IF ERRORS>0 THEN EXIT PROCEDURE END IF
|
||||
NN=N ! wrap around boundary
|
||||
P=-1 ! start here
|
||||
WHILE N<>S DO ! until survivor count is met
|
||||
FOUND=0 ! start looking
|
||||
WHILE FOUND<>K DO ! until we have the k-th prisoner
|
||||
P+=1
|
||||
IF P=NN THEN P=0 END IF ! wrap around
|
||||
IF DEAD[P]<>1 THEN
|
||||
FOUND+=1
|
||||
END IF ! if prisoner is alive increment found
|
||||
END WHILE
|
||||
DEAD[P]=1 ! kill the unlucky one
|
||||
KILLED$=KILLED$+STR$(P) ! build killed list
|
||||
N-=1 ! reduce size of circle
|
||||
END WHILE
|
||||
FOR I=0 TO NN-1 DO
|
||||
IF DEAD[I]<>1 THEN
|
||||
SURVIVED$=SURVIVED$+STR$(I) ! build survivor list
|
||||
END IF
|
||||
END FOR
|
||||
PRINT("Killed:";KILLED$)
|
||||
PRINT("Survived:";SURVIVED$)
|
||||
END PROCEDURE
|
||||
|
||||
BEGIN
|
||||
ERRORS=0
|
||||
MAIN(5,2,1->ERRORS)
|
||||
MAIN(41,3,1->ERRORS)
|
||||
MAIN(41,3,3->ERRORS)
|
||||
END PROGRAM
|
||||
Loading…
Add table
Add a link
Reference in a new issue