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
20
Task/Josephus-problem/Nim/josephus-problem.nim
Normal file
20
Task/Josephus-problem/Nim/josephus-problem.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import sequtils, strutils, future
|
||||
|
||||
proc j(n, k): string =
|
||||
var
|
||||
p = toSeq(0 .. < n)
|
||||
i = 0
|
||||
s = newSeq[int]()
|
||||
|
||||
while p.len > 0:
|
||||
i = (i + k - 1) mod p.len
|
||||
s.add p[i]
|
||||
system.delete(p, i)
|
||||
|
||||
result = "Prisoner killing order: "
|
||||
result.add s.map((x: int) => $x).join(", ")
|
||||
result.add ".\nSurvivor: "
|
||||
result.add($s[s.high])
|
||||
|
||||
echo j(5,2)
|
||||
echo j(41,3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue