Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
"Next!" (Using itertools.cycle) solution in Clear category for Gator And Ducks by adamspj
from itertools import cycle
def gator(ducks: int, step: int) -> list[int]:
duck_sequence = [0] * ducks
circle = cycle(range(0, ducks))
dead_ducks = 0
while dead_ducks < ducks: # While their not all eaten yet
for _ in range(step):
victim = next(circle)
while duck_sequence[victim]: # If chosen "victim" already dead, keep looking to next
victim = next(circle)
dead_ducks += 1
duck_sequence[victim] = dead_ducks
return duck_sequence
March 17, 2024
Comments: