Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Josephus-problem/Icon/josephus-problem-1.icon
Normal file
9
Task/Josephus-problem/Icon/josephus-problem-1.icon
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
procedure main(A)
|
||||
m := integer(A[1]) | 41
|
||||
c := integer(A[2]) | 3
|
||||
write("With ",m," men, counting to ",c," last position is: ", j(m,c))
|
||||
end
|
||||
|
||||
procedure j(m,c)
|
||||
return if m==1 then 0 else (j(m-1,c)+c)%m
|
||||
end
|
||||
27
Task/Josephus-problem/Icon/josephus-problem-2.icon
Normal file
27
Task/Josephus-problem/Icon/josephus-problem-2.icon
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue