RosettaCodeData/Task/Josephus-problem/Icon/josephus-problem-2.icon

28 lines
625 B
Plaintext

procedure main(args)
n := total := integer(args[1]) | 41 # Number of people
k := count := integer(args[2]) | 3 # Count
s := integer(args[3])-1 | 0 # Number to save
write("With ",n," people, counting by ",k,", the ",s+1," safe places are:")
every write("\t",j(n,k,(n-s) to n))
end
procedure j(n,k,s)
a := k*(n-s) + 1
q := k/(k-1.0)
nk := n*k
olda := a
while a <= nk do {
olda := a
a := ceil(a,q)
}
t := nk - olda
return t
end
procedure ceil(a,q)
n := a*q
if n = integer(n) then return integer(n)
n ?:= integer(tab(upto('.'))) + 1
return n
end