diff --git a/2020/Python/day23.py b/2020/Python/day23.py new file mode 100644 index 0000000..19fecf2 --- /dev/null +++ b/2020/Python/day23.py @@ -0,0 +1,35 @@ + +def move_cups(cups: list[int]) -> list[int]: + cups_round = cups[:] + current = cups_round.pop(0) + taken = [cups_round.pop(0), cups_round.pop(0), cups_round.pop(0)] + + minimum, maximum = min(cups_round), max(cups_round) + + destination = current + while (destination := destination - 1) in taken or destination < minimum: + if destination < minimum: + destination = maximum + 1 + + for i in range(len(cups_round)): + if cups_round[i] == destination: + for taken_cup in reversed(taken): + cups_round.insert(i+1, taken_cup) + break + + cups_round.append(current) + return cups_round + + +def solve_p1(order: str, n: int) -> str: + table = [int(x) for x in order] + for i in range(n): + table = move_cups(table) + + for i in range(len(table)): + if table[i] == 1: + return "".join([str(table[x%len(table)]) for x in range(i+1, len(table)+i)]) + return "" + + +print(solve_p1("389547612", 100))