langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
33
Task/Josephus-problem/NetRexx/josephus-problem.netrexx
Normal file
33
Task/Josephus-problem/NetRexx/josephus-problem.netrexx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
/* REXX **************************************************************
|
||||
* 15.11.2012 Walter Pachl - my own solution
|
||||
* 16.11.2012 Walter Pachl generalized n prisoners + w killing distance
|
||||
* and s=number of survivors
|
||||
**********************************************************************/
|
||||
dead = 0 /* nobody's dead yet */
|
||||
n = 41 /* number of alive prisoners */
|
||||
nn = n /* wrap around boundary */
|
||||
w = 3 /* killing count */
|
||||
s = 1 /* nuber of survivors */
|
||||
p = -1 /* start here */
|
||||
killed = '' /* output of killings */
|
||||
Loop until n = s /* until one alive prisoner */
|
||||
found = 0 /* start looking */
|
||||
Loop Until found = w /* until we have the third */
|
||||
p = p + 1 /* next position */
|
||||
If p = nn Then p = 0 /* wrap around */
|
||||
If dead[p] = 0 Then /* a prisoner who is alive */
|
||||
found = found + 1 /* increment found count */
|
||||
End
|
||||
dead[p] = 1
|
||||
n = n - 1 /* shoot the one on this pos. */
|
||||
killed = killed p /* add to output */
|
||||
End /* End of main loop */
|
||||
Say 'killed:'killed.subword(1, 20) /* output killing sequence */
|
||||
Say ' 'killed.subword(21) /* output killing sequence */
|
||||
Say 'Survivor(s):' /* show */
|
||||
Loop i = 0 To 40 /* look for the surviving p's */
|
||||
If dead[i] = 0 Then Say i /* found one */
|
||||
End
|
||||
1
Task/Josephus-problem/PARI-GP/josephus-problem.pari
Normal file
1
Task/Josephus-problem/PARI-GP/josephus-problem.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
Josephus(n, k)=if(n<2, n>0, my(t=(Josephus(n-1, k)+k)%n); if(t, t, n))
|
||||
10
Task/Josephus-problem/Perl-6/josephus-problem-1.pl6
Normal file
10
Task/Josephus-problem/Perl-6/josephus-problem-1.pl6
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
sub Execute(@prisoner is rw, $k) {
|
||||
until @prisoner == 1 {
|
||||
@prisoner.=rotate($k - 1);
|
||||
@prisoner.shift;
|
||||
}
|
||||
}
|
||||
|
||||
my @prisoner = ^41;
|
||||
Execute @prisoner, 3;
|
||||
say "Prisoner {@prisoner} survived.";
|
||||
3
Task/Josephus-problem/Perl-6/josephus-problem-2.pl6
Normal file
3
Task/Josephus-problem/Perl-6/josephus-problem-2.pl6
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
my @dalton = <Joe Jack William Averell Rantanplan>;
|
||||
Execute @dalton, 2;
|
||||
say "{@dalton} survived.";
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#1 = 41 // number of prisoners
|
||||
#2 = 3 // step size
|
||||
#3 = 1 // number of survivors
|
||||
|
||||
Buf_Switch(Buf_Free)
|
||||
for (#5=0; #5<#1; #5++) {
|
||||
Ins_Text("prisoner ") Num_Ins(#5, LEFT)
|
||||
}
|
||||
|
||||
BOF
|
||||
#4=1
|
||||
while (#1 > #3) {
|
||||
if (#4++ % #2 == 0) {
|
||||
Del_Line(1)
|
||||
#1--
|
||||
} else {
|
||||
Line(1)
|
||||
}
|
||||
if (At_EOF) { BOF }
|
||||
}
|
||||
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