Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Gator And Ducks by Molot
def gator(ducks: int, step: int) -> list[int]:
avail = [1]*ducks
res = [0]*ducks
cnt = step
i, j, cnt = 0, 1, step
while sum(avail) != 0:
if avail[i] == 1:
cnt -= 1
if cnt == 0:
avail[i] = 0
res[i] = j
cnt, j = step, j + 1
i = (i + 1) % ducks
return res
print("Example:")
print(gator(3, 2))
# These "asserts" are used for self-checking
assert gator(8, 4) == [5, 4, 6, 1, 3, 8, 7, 2]
assert gator(7, 11) == [7, 2, 3, 1, 5, 6, 4]
assert gator(3, 1) == [1, 2, 3]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 10, 2025