Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
2
Task/Josephus-problem/J/josephus-problem-1.j
Normal file
2
Task/Josephus-problem/J/josephus-problem-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
3 ([ (1 }. <:@[ |. ])^:(1 < #@])^:_ i.@]) 41
|
||||
30
|
||||
7
Task/Josephus-problem/J/josephus-problem-2.j
Normal file
7
Task/Josephus-problem/J/josephus-problem-2.j
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
DropNext=. 1 }. <:@[ |. ]
|
||||
MoreThanOne=. 1 < #@]
|
||||
WhileMoreThanOne=. (^:MoreThanOne f.) (^:_)
|
||||
prisoners=. i.@]
|
||||
|
||||
[ DropNext WhileMoreThanOne prisoners f.
|
||||
[ (1 }. <:@[ |. ])^:(1 < #@])^:_ i.@]
|
||||
15
Task/Josephus-problem/J/josephus-problem-3.j
Normal file
15
Task/Josephus-problem/J/josephus-problem-3.j
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Josephus =: dyad define NB. explicit form, assume executioner starts at position 0
|
||||
NB. use: SKIP josephus NUMBER_OF_PRISONERS
|
||||
N =: y
|
||||
K =: N | x
|
||||
EXECUTIONER =: 0
|
||||
PRISONERS =: i. N
|
||||
kill =: ] #~ (~: ([: i. #))
|
||||
while. 1 (< #) PRISONERS do.
|
||||
EXECUTIONER =: (# PRISONERS) | <: K + EXECUTIONER
|
||||
PRISONERS =: EXECUTIONER kill PRISONERS
|
||||
end.
|
||||
)
|
||||
|
||||
3 Josephus 41
|
||||
30
|
||||
5
Task/Josephus-problem/J/josephus-problem-4.j
Normal file
5
Task/Josephus-problem/J/josephus-problem-4.j
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
NB. this is a direct translation of the algo from C code above.
|
||||
Josephus2 =: 4 : '(| x&+)/i. - 1+y'
|
||||
|
||||
3 Josephus2 41
|
||||
30
|
||||
Loading…
Add table
Add a link
Reference in a new issue