Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
on josephus(n, k, s)
|
||||
script o
|
||||
property living : {}
|
||||
end script
|
||||
|
||||
repeat with i from 1 to n
|
||||
set end of o's living to i
|
||||
end repeat
|
||||
|
||||
set startPosition to k
|
||||
repeat until (n = s) -- Keep going round the circle until only s prisoners remain.
|
||||
set circleSize to n
|
||||
if (n < k) then
|
||||
set i to (startPosition - 1) mod circleSize + 1
|
||||
set item i of o's living to missing value
|
||||
set n to n - 1
|
||||
else
|
||||
repeat with i from startPosition to circleSize by k
|
||||
set item i of o's living to missing value
|
||||
set n to n - 1
|
||||
if (n = s) then exit repeat
|
||||
end repeat
|
||||
end if
|
||||
set startPosition to i + k - circleSize
|
||||
set o's living to o's living's integers
|
||||
end repeat
|
||||
|
||||
return o's living
|
||||
end josephus
|
||||
|
||||
josephus(41, 3, 1) --> {31}
|
||||
josephus(41, 3, 6) --> {2, 4, 16, 22, 31, 35}
|
||||
Loading…
Add table
Add a link
Reference in a new issue