diff --git a/days1-5/day5/day5.py b/days1-5/day5/day5.py new file mode 100644 index 0000000..4485b21 --- /dev/null +++ b/days1-5/day5/day5.py @@ -0,0 +1,60 @@ +def main() -> None: + with open('input.txt', 'r') as f: + input_content = f.read() + crate_input_content, moves_input_content = input_content.split('\n\n') + + crates_dictionary = { + 1: [], + 2: [], + 3: [], + 4: [], + 5: [], + 6: [], + 7: [], + 8: [], + 9: [], + } + crates_dictionary_builder(crates_dictionary, crate_input_content) + move_list = move_list_builder(moves_input_content) + + print(crates_dictionary) + + for move in move_list: + crates_moved = crates_dictionary[move[1]][:move[0]] + for i in range(move[0]): + crates_dictionary[move[1]].remove(crates_dictionary[move[1]][0]) + for crate in crates_moved[::-1]: # Remove [::-1] for part 1 + crates_dictionary[move[2]].insert(0, crate) + print(crates_dictionary) + + for crates in crates_dictionary.values(): + print(crates[0], end='') + + +def crates_dictionary_builder(c_dict: dict, content: str) -> None: + content_lines = content[:-1].splitlines() + for line in content_lines: + first_crate = 0 + if line[first_crate] == '[': + c_dict[1].append(line[1]) + while '[' in line[first_crate+1:]: + try: + first_crate = line.index('[', first_crate+1) + except ValueError: + print('a') + c_dict[first_crate//4+1] += line[first_crate+1] + + +def move_list_builder(content: str) -> list[tuple]: + moves_content = content.splitlines() + move_list = [] + for move in moves_content: + move = move[5:] + moved, rest = move.split(' from ') + moved_from, moved_to = rest.split(' to ') + move_list.append((int(moved), int(moved_from), int(moved_to))) + return move_list + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/days1-5/day5/input.txt b/days1-5/day5/input.txt new file mode 100644 index 0000000..9833f09 --- /dev/null +++ b/days1-5/day5/input.txt @@ -0,0 +1,512 @@ + [V] [C] [M] +[V] [J] [N] [H] [V] +[R] [F] [N] [W] [Z] [N] +[H] [R] [D] [Q] [M] [L] [B] +[B] [C] [H] [V] [R] [C] [G] [R] +[G] [G] [F] [S] [D] [H] [B] [R] [S] +[D] [N] [S] [D] [H] [G] [J] [J] [G] +[W] [J] [L] [J] [S] [P] [F] [S] [L] + 1 2 3 4 5 6 7 8 9 + +move 2 from 2 to 7 +move 8 from 5 to 6 +move 2 from 4 to 5 +move 1 from 4 to 5 +move 1 from 5 to 8 +move 5 from 9 to 2 +move 7 from 1 to 6 +move 7 from 3 to 8 +move 1 from 4 to 6 +move 2 from 5 to 6 +move 6 from 7 to 5 +move 2 from 2 to 4 +move 4 from 5 to 2 +move 10 from 8 to 1 +move 2 from 7 to 4 +move 4 from 2 to 8 +move 2 from 9 to 8 +move 1 from 8 to 4 +move 2 from 4 to 9 +move 5 from 8 to 2 +move 1 from 4 to 6 +move 1 from 8 to 9 +move 1 from 7 to 2 +move 2 from 4 to 2 +move 1 from 7 to 3 +move 13 from 2 to 1 +move 1 from 2 to 4 +move 1 from 2 to 3 +move 2 from 5 to 4 +move 17 from 6 to 4 +move 3 from 4 to 9 +move 14 from 1 to 4 +move 4 from 6 to 8 +move 1 from 9 to 8 +move 23 from 4 to 8 +move 6 from 1 to 7 +move 3 from 1 to 5 +move 1 from 3 to 8 +move 5 from 7 to 8 +move 1 from 3 to 4 +move 1 from 5 to 3 +move 1 from 5 to 1 +move 1 from 3 to 2 +move 1 from 9 to 4 +move 9 from 4 to 9 +move 1 from 1 to 2 +move 11 from 8 to 2 +move 1 from 4 to 5 +move 13 from 2 to 3 +move 7 from 9 to 6 +move 1 from 5 to 6 +move 1 from 5 to 2 +move 1 from 9 to 4 +move 1 from 4 to 9 +move 2 from 8 to 9 +move 1 from 7 to 8 +move 8 from 9 to 1 +move 8 from 1 to 4 +move 4 from 6 to 7 +move 1 from 9 to 4 +move 2 from 3 to 9 +move 1 from 9 to 1 +move 6 from 4 to 1 +move 2 from 1 to 3 +move 22 from 8 to 6 +move 1 from 2 to 5 +move 3 from 7 to 8 +move 15 from 6 to 4 +move 7 from 3 to 7 +move 4 from 6 to 9 +move 2 from 9 to 2 +move 6 from 3 to 5 +move 3 from 9 to 5 +move 5 from 5 to 8 +move 1 from 2 to 1 +move 6 from 8 to 2 +move 1 from 1 to 2 +move 3 from 5 to 3 +move 1 from 7 to 2 +move 4 from 7 to 8 +move 4 from 6 to 1 +move 1 from 5 to 1 +move 4 from 8 to 7 +move 2 from 3 to 2 +move 1 from 1 to 3 +move 15 from 4 to 2 +move 3 from 7 to 3 +move 4 from 7 to 2 +move 1 from 4 to 9 +move 5 from 3 to 8 +move 29 from 2 to 1 +move 1 from 9 to 5 +move 1 from 2 to 1 +move 11 from 1 to 5 +move 1 from 4 to 5 +move 2 from 6 to 3 +move 1 from 3 to 4 +move 16 from 1 to 9 +move 4 from 8 to 4 +move 3 from 6 to 9 +move 1 from 3 to 7 +move 1 from 7 to 3 +move 6 from 1 to 6 +move 3 from 4 to 3 +move 3 from 8 to 5 +move 3 from 1 to 8 +move 3 from 1 to 4 +move 2 from 4 to 9 +move 3 from 6 to 3 +move 15 from 5 to 2 +move 3 from 2 to 3 +move 4 from 2 to 7 +move 2 from 5 to 9 +move 10 from 3 to 6 +move 11 from 9 to 5 +move 2 from 4 to 9 +move 8 from 9 to 4 +move 1 from 9 to 6 +move 7 from 4 to 6 +move 3 from 5 to 8 +move 22 from 6 to 9 +move 4 from 7 to 8 +move 8 from 5 to 8 +move 2 from 4 to 3 +move 1 from 8 to 1 +move 17 from 8 to 3 +move 3 from 3 to 4 +move 13 from 3 to 9 +move 20 from 9 to 7 +move 2 from 2 to 9 +move 19 from 9 to 5 +move 1 from 1 to 4 +move 3 from 2 to 7 +move 4 from 4 to 3 +move 1 from 9 to 8 +move 18 from 5 to 1 +move 1 from 9 to 4 +move 1 from 9 to 7 +move 2 from 4 to 8 +move 1 from 5 to 4 +move 3 from 2 to 7 +move 3 from 3 to 1 +move 2 from 1 to 3 +move 3 from 3 to 8 +move 1 from 4 to 8 +move 6 from 8 to 2 +move 1 from 3 to 9 +move 1 from 3 to 9 +move 10 from 1 to 9 +move 7 from 1 to 7 +move 4 from 7 to 4 +move 29 from 7 to 3 +move 6 from 2 to 9 +move 25 from 3 to 6 +move 5 from 3 to 9 +move 13 from 6 to 9 +move 12 from 6 to 2 +move 1 from 8 to 9 +move 10 from 2 to 6 +move 7 from 6 to 5 +move 20 from 9 to 3 +move 11 from 3 to 6 +move 1 from 7 to 9 +move 2 from 2 to 9 +move 19 from 9 to 2 +move 14 from 6 to 8 +move 4 from 5 to 2 +move 2 from 4 to 6 +move 3 from 5 to 1 +move 13 from 8 to 5 +move 1 from 6 to 1 +move 2 from 4 to 2 +move 8 from 2 to 4 +move 6 from 4 to 7 +move 1 from 9 to 8 +move 2 from 4 to 7 +move 5 from 2 to 4 +move 4 from 4 to 2 +move 10 from 5 to 6 +move 1 from 1 to 7 +move 1 from 5 to 4 +move 1 from 4 to 9 +move 4 from 7 to 8 +move 5 from 1 to 7 +move 1 from 9 to 7 +move 7 from 3 to 2 +move 2 from 5 to 2 +move 8 from 6 to 9 +move 1 from 4 to 6 +move 3 from 7 to 4 +move 5 from 9 to 7 +move 2 from 4 to 3 +move 20 from 2 to 4 +move 2 from 4 to 8 +move 14 from 4 to 2 +move 12 from 7 to 4 +move 8 from 2 to 1 +move 10 from 2 to 4 +move 6 from 8 to 5 +move 1 from 7 to 8 +move 4 from 4 to 3 +move 1 from 3 to 9 +move 1 from 2 to 7 +move 1 from 6 to 8 +move 5 from 3 to 5 +move 1 from 3 to 2 +move 7 from 4 to 5 +move 6 from 1 to 7 +move 5 from 7 to 6 +move 1 from 6 to 5 +move 2 from 7 to 8 +move 1 from 2 to 6 +move 2 from 8 to 2 +move 5 from 5 to 7 +move 6 from 6 to 8 +move 16 from 4 to 9 +move 16 from 9 to 4 +move 11 from 5 to 4 +move 5 from 8 to 3 +move 2 from 5 to 2 +move 14 from 4 to 2 +move 1 from 6 to 3 +move 1 from 6 to 9 +move 1 from 5 to 3 +move 3 from 8 to 2 +move 10 from 4 to 7 +move 5 from 9 to 2 +move 3 from 4 to 7 +move 1 from 1 to 4 +move 3 from 2 to 5 +move 2 from 3 to 7 +move 1 from 4 to 2 +move 18 from 2 to 8 +move 3 from 8 to 4 +move 5 from 3 to 1 +move 1 from 3 to 9 +move 1 from 9 to 3 +move 8 from 8 to 7 +move 2 from 5 to 4 +move 1 from 5 to 6 +move 1 from 2 to 5 +move 1 from 5 to 8 +move 1 from 6 to 9 +move 3 from 2 to 7 +move 27 from 7 to 4 +move 2 from 2 to 4 +move 4 from 8 to 4 +move 1 from 9 to 8 +move 3 from 1 to 6 +move 1 from 3 to 5 +move 3 from 8 to 3 +move 1 from 1 to 4 +move 1 from 8 to 1 +move 3 from 1 to 4 +move 2 from 8 to 2 +move 2 from 6 to 2 +move 8 from 4 to 9 +move 1 from 7 to 1 +move 1 from 5 to 4 +move 1 from 7 to 3 +move 4 from 2 to 7 +move 1 from 8 to 6 +move 8 from 9 to 7 +move 1 from 6 to 3 +move 3 from 3 to 4 +move 37 from 4 to 1 +move 1 from 4 to 5 +move 13 from 7 to 8 +move 6 from 8 to 4 +move 5 from 8 to 3 +move 1 from 7 to 6 +move 4 from 1 to 5 +move 1 from 6 to 5 +move 2 from 8 to 4 +move 32 from 1 to 5 +move 1 from 1 to 4 +move 5 from 3 to 5 +move 1 from 3 to 2 +move 1 from 2 to 9 +move 19 from 5 to 2 +move 1 from 9 to 1 +move 16 from 5 to 1 +move 7 from 5 to 6 +move 1 from 3 to 1 +move 11 from 1 to 2 +move 18 from 2 to 4 +move 1 from 5 to 9 +move 8 from 6 to 1 +move 10 from 2 to 6 +move 7 from 4 to 9 +move 2 from 2 to 1 +move 7 from 4 to 2 +move 5 from 4 to 5 +move 2 from 9 to 6 +move 9 from 6 to 3 +move 5 from 5 to 3 +move 8 from 4 to 9 +move 7 from 9 to 8 +move 4 from 2 to 9 +move 10 from 3 to 1 +move 6 from 8 to 1 +move 2 from 6 to 3 +move 5 from 3 to 8 +move 3 from 2 to 7 +move 1 from 9 to 5 +move 1 from 3 to 5 +move 2 from 7 to 8 +move 1 from 8 to 9 +move 1 from 6 to 1 +move 23 from 1 to 4 +move 2 from 5 to 3 +move 1 from 8 to 2 +move 2 from 8 to 5 +move 2 from 5 to 6 +move 1 from 2 to 7 +move 1 from 7 to 5 +move 4 from 9 to 7 +move 1 from 7 to 5 +move 1 from 3 to 6 +move 3 from 7 to 4 +move 1 from 3 to 8 +move 1 from 4 to 6 +move 6 from 1 to 8 +move 4 from 6 to 4 +move 2 from 9 to 1 +move 1 from 5 to 1 +move 19 from 4 to 2 +move 2 from 9 to 3 +move 1 from 9 to 3 +move 9 from 1 to 8 +move 1 from 5 to 8 +move 1 from 9 to 3 +move 2 from 3 to 9 +move 3 from 8 to 4 +move 1 from 4 to 9 +move 1 from 9 to 5 +move 2 from 3 to 4 +move 6 from 4 to 7 +move 3 from 9 to 5 +move 4 from 4 to 7 +move 1 from 5 to 6 +move 18 from 2 to 7 +move 13 from 7 to 9 +move 3 from 5 to 1 +move 1 from 2 to 1 +move 1 from 6 to 5 +move 3 from 1 to 7 +move 1 from 1 to 5 +move 7 from 9 to 6 +move 8 from 7 to 4 +move 11 from 7 to 6 +move 5 from 9 to 2 +move 17 from 6 to 1 +move 2 from 5 to 1 +move 11 from 8 to 1 +move 20 from 1 to 2 +move 3 from 8 to 1 +move 1 from 9 to 8 +move 1 from 6 to 1 +move 11 from 1 to 7 +move 18 from 2 to 3 +move 12 from 4 to 8 +move 11 from 7 to 3 +move 7 from 2 to 3 +move 2 from 1 to 5 +move 1 from 1 to 3 +move 1 from 8 to 1 +move 1 from 5 to 9 +move 1 from 9 to 6 +move 1 from 8 to 7 +move 1 from 5 to 3 +move 1 from 6 to 7 +move 2 from 8 to 1 +move 8 from 3 to 2 +move 7 from 2 to 9 +move 6 from 8 to 6 +move 1 from 9 to 3 +move 2 from 6 to 4 +move 5 from 9 to 6 +move 7 from 6 to 2 +move 8 from 2 to 9 +move 2 from 1 to 9 +move 2 from 7 to 2 +move 2 from 4 to 8 +move 1 from 2 to 7 +move 25 from 3 to 7 +move 7 from 9 to 7 +move 1 from 2 to 5 +move 1 from 1 to 4 +move 3 from 8 to 1 +move 3 from 1 to 8 +move 3 from 7 to 8 +move 15 from 7 to 3 +move 10 from 8 to 3 +move 1 from 5 to 7 +move 1 from 8 to 5 +move 3 from 9 to 2 +move 1 from 6 to 4 +move 2 from 2 to 7 +move 1 from 2 to 5 +move 14 from 7 to 9 +move 1 from 6 to 2 +move 1 from 7 to 1 +move 1 from 5 to 4 +move 3 from 4 to 3 +move 1 from 7 to 6 +move 1 from 2 to 7 +move 1 from 1 to 2 +move 3 from 9 to 1 +move 1 from 6 to 2 +move 2 from 2 to 6 +move 17 from 3 to 6 +move 1 from 8 to 3 +move 1 from 5 to 4 +move 2 from 7 to 2 +move 9 from 9 to 8 +move 1 from 9 to 3 +move 16 from 3 to 2 +move 1 from 7 to 5 +move 5 from 6 to 5 +move 1 from 1 to 6 +move 1 from 4 to 1 +move 1 from 9 to 3 +move 9 from 8 to 6 +move 3 from 1 to 5 +move 1 from 9 to 1 +move 16 from 2 to 1 +move 2 from 2 to 7 +move 2 from 3 to 9 +move 2 from 7 to 4 +move 2 from 9 to 3 +move 3 from 3 to 5 +move 1 from 4 to 5 +move 1 from 4 to 2 +move 1 from 1 to 7 +move 1 from 7 to 1 +move 1 from 3 to 6 +move 2 from 5 to 1 +move 3 from 6 to 2 +move 2 from 5 to 8 +move 8 from 5 to 4 +move 1 from 5 to 3 +move 1 from 3 to 2 +move 1 from 8 to 3 +move 1 from 3 to 8 +move 4 from 1 to 7 +move 9 from 1 to 7 +move 6 from 1 to 8 +move 3 from 7 to 4 +move 7 from 6 to 7 +move 11 from 4 to 3 +move 2 from 3 to 8 +move 8 from 3 to 8 +move 4 from 6 to 1 +move 1 from 7 to 4 +move 2 from 1 to 2 +move 8 from 7 to 2 +move 1 from 4 to 8 +move 10 from 8 to 2 +move 2 from 6 to 1 +move 1 from 1 to 4 +move 1 from 4 to 8 +move 2 from 1 to 4 +move 6 from 6 to 5 +move 1 from 1 to 9 +move 2 from 6 to 8 +move 1 from 4 to 5 +move 1 from 6 to 9 +move 4 from 8 to 9 +move 1 from 7 to 1 +move 6 from 8 to 6 +move 1 from 6 to 1 +move 1 from 4 to 9 +move 2 from 9 to 5 +move 5 from 5 to 9 +move 8 from 9 to 5 +move 2 from 8 to 5 +move 3 from 6 to 9 +move 8 from 5 to 7 +move 5 from 5 to 6 +move 1 from 9 to 2 +move 1 from 3 to 1 +move 1 from 6 to 7 +move 1 from 5 to 6 +move 24 from 2 to 4 +move 3 from 9 to 7 +move 16 from 4 to 5 +move 2 from 1 to 3 +move 12 from 5 to 6 +move 1 from 9 to 5 +move 4 from 5 to 9 +move 1 from 1 to 6 +move 1 from 5 to 2 +move 2 from 9 to 8 +move 1 from 8 to 1 +move 5 from 4 to 5 +move 2 from 3 to 5 +move 1 from 8 to 3 +move 1 from 1 to 6 +move 3 from 5 to 7 +move 1 from 9 to 1 +move 1 from 2 to 8 \ No newline at end of file