Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Bubble solution in Clear category for Draw Ghost Legs by amandel
def draw_ghost_legs(result: list[int]) -> list[tuple[int, int]]:
res = result[:]
legs = []
while True:
for i in range(len(res)-1):
if res[i] > res[i+1]:
res[i] , res[i+1] = res[i+1] , res[i]
legs.append((i+1, i+2))
break
else:
break
return legs[::-1]
print("Example:")
print(draw_ghost_legs([3, 2, 1]))
def checker(func: callable, result: list[int]):
your_result = [r for r in sorted(result)]
for a, b in func(result):
your_result[a - 1], your_result[b - 1] = your_result[b - 1], your_result[a - 1]
return your_result == result
# These "asserts" are used for self-checking
assert checker(draw_ghost_legs, [3, 2, 1]) is True
assert checker(draw_ghost_legs, [3, 2, 4, 1]) is True
assert checker(draw_ghost_legs, [1, 5, 4, 2, 3]) is True
assert checker(draw_ghost_legs, [2, 3, 4, 5, 6, 1]) is True
print("The mission is done! Click 'Check Solution' to earn rewards!")
April 8, 2025
Comments: