From 7a2cf881a16515fdb6a5b4887bfebf996d4b70a0 Mon Sep 17 00:00:00 2001 From: James Hallam Date: Mon, 11 Dec 2023 12:12:08 +0000 Subject: [PATCH] Updating naming convention --- 1/1-1.py | 2 +- 1/1-2.py | 2 +- 10/10-v.py | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2/2-1.py | 2 +- 2/2-2.py | 2 +- 3/3-1.py | 2 +- 3/3-2.py | 2 +- 4/4-1.py | 2 +- 4/4-2.py | 2 +- 5/5-1.py | 2 +- 5/5-2.py | 2 +- 7/7-1.py | 4 +- 7/7-2.py | 2 +- 8/8-1.py | 2 +- 8/8-2.py | 2 +- 9/9-1.py | 2 +- 9/9-2.py | 2 +- 17 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 10/10-v.py diff --git a/1/1-1.py b/1/1-1.py index edad076..8fd596b 100644 --- a/1/1-1.py +++ b/1/1-1.py @@ -7,7 +7,7 @@ def get_alpha_regex(): def get_input(): regex = get_alpha_regex() - with open("one.txt", "r") as f: + with open("1.txt", "r") as f: return [regex.sub("", l) for l in f.read().splitlines()] diff --git a/1/1-2.py b/1/1-2.py index d440cc2..0d006d2 100644 --- a/1/1-2.py +++ b/1/1-2.py @@ -18,7 +18,7 @@ def get_alpha_regex(): def get_input(): - with open("one.txt", "r") as f: + with open("1.txt", "r") as f: return f.read().splitlines() diff --git a/10/10-v.py b/10/10-v.py new file mode 100644 index 0000000..2e057e5 --- /dev/null +++ b/10/10-v.py @@ -0,0 +1,109 @@ +import matplotlib.pyplot as plt +import numpy as np +import time +import os + +DIRECTION_MAP = { + "|": [[1, 0], [-1, 0]], + "-": [[0, 1], [0, -1]], + "J": [[-1, 0], [0, -1]], + "L": [[-1, 0], [0, 1]], + "7": [[1, 0], [0, -1]], + "F": [[1, 0], [0, 1]], + "S": [[-1, 0], [0, 1]], +} +SYMBOL_MAP = { + "|": "|", + "-": "-", + "J": "┛", + "L": "┗", + "7": "┓", + "F": "┏", + "S": "┗", + ".": " " +} + + +def get_input(): + with open("10.txt", "r") as f: + return [l.strip() for l in f.readlines()] + +def find_start(input): + for i, l in enumerate(input): + for j, c in enumerate(l): + if c == "S": + return [i, j] + + +def get_next(input, current_coords, prev_coords): + y, x = current_coords + current_val = input[y][x] + possibles = DIRECTION_MAP[current_val] + for pos in possibles: + next_coords = [y + pos[0], x + pos[1]] + if next_coords == prev_coords: + continue + return input[next_coords[0]][next_coords[1]], next_coords + + +def print_slice(input, current_coords, prev_list): + PREV_COLOR = '\033[92m' + END_C = '\033[0m' + upper_y, lower_y = current_coords[0] - 20, current_coords[0] + 20 + upper_x, lower_x = current_coords[1] - 40, current_coords[1] + 40 + if upper_y < 0: + lower_y -= upper_y + upper_y = 0 + if upper_x < 0: + lower_x -= upper_x + upper_x = 0 + if lower_y > len(input): + upper_y += len(input) - lower_y + lower_y = len(input) + if lower_x > len(input[0]): + upper_x += len(input[0]) - lower_x + lower_x = len(input[0]) + slice = [list(r) for r in input[upper_y:lower_y]] + for i, l in enumerate(slice): + slice[i] = l[upper_x:lower_x] + for i, l in enumerate(slice): + for j, c in enumerate(l): + if [i + upper_y, j + upper_x] in prev_list: + slice[i][j] = f"{PREV_COLOR}{c}{END_C}" + os.system("clear") + for l in slice: + print("".join(l)) + print("\n") + time.sleep(0.1) + + +def get_furthest(input, symbols): + start = find_start(input) + count = 0 + prev = start + prev_list = [start] + current_coords = start + while True: + print_slice(symbols, current_coords, prev_list) + count += 1 + next_val, next_coords = get_next(input, current_coords, prev) + if next_val == "S": + return count / 2 + prev = current_coords + current_coords = next_coords + prev_list.append(current_coords) + +def find_start(input): + for i, l in enumerate(input): + for j, c in enumerate(l): + if c == "S": + return [i, j] + +def main(): + input = get_input() + symbol_representation = [[SYMBOL_MAP[c] for c in l] for l in input] + print_slice(symbol_representation, find_start(input), [find_start(input)]) + time.sleep(0.5) + get_furthest(input, symbol_representation) + +main() \ No newline at end of file diff --git a/2/2-1.py b/2/2-1.py index c64de95..f9af083 100644 --- a/2/2-1.py +++ b/2/2-1.py @@ -2,7 +2,7 @@ def get_input(): - with open("two.txt", "r") as f: + with open("2.txt", "r") as f: return [ l.replace("Game", "").replace("\n", "").split(":") for l in f.readlines() ] diff --git a/2/2-2.py b/2/2-2.py index 8a12649..90e957a 100644 --- a/2/2-2.py +++ b/2/2-2.py @@ -1,5 +1,5 @@ def get_input(): - with open("two.txt", "r") as f: + with open("2.txt", "r") as f: return [ l.replace("Game", "").replace("\n", "").split(":") for l in f.readlines() ] diff --git a/3/3-1.py b/3/3-1.py index 81aa7b6..e61eef9 100644 --- a/3/3-1.py +++ b/3/3-1.py @@ -1,5 +1,5 @@ def get_input(): - with open("three.txt", "r") as f: + with open("3.txt", "r") as f: return f.readlines() diff --git a/3/3-2.py b/3/3-2.py index f293369..6d476dc 100644 --- a/3/3-2.py +++ b/3/3-2.py @@ -1,5 +1,5 @@ def get_input(): - with open("three.txt", "r") as f: + with open("3.txt", "r") as f: return f.readlines() diff --git a/4/4-1.py b/4/4-1.py index 2826fa8..1299113 100644 --- a/4/4-1.py +++ b/4/4-1.py @@ -1,5 +1,5 @@ def get_input(): - with open("four.txt", "r") as f: + with open("4.txt", "r") as f: return [l.strip().split("\n") for l in f.readlines() if l != ""] diff --git a/4/4-2.py b/4/4-2.py index 66dceb9..91b0962 100644 --- a/4/4-2.py +++ b/4/4-2.py @@ -1,5 +1,5 @@ def get_input(): - with open("four.txt", "r") as f: + with open("4.txt", "r") as f: return [l.strip().split("\n") for l in f.readlines() if l != ""] diff --git a/5/5-1.py b/5/5-1.py index e414467..69721b6 100644 --- a/5/5-1.py +++ b/5/5-1.py @@ -1,5 +1,5 @@ def get_input(): - with open("five.txt", "r") as f: + with open("5.txt", "r") as f: return f.readlines() diff --git a/5/5-2.py b/5/5-2.py index ffa7233..f408749 100644 --- a/5/5-2.py +++ b/5/5-2.py @@ -2,7 +2,7 @@ def get_input(): - with open("fivetest.txt", "r") as f: + with open("5.txt", "r") as f: return f.readlines() diff --git a/7/7-1.py b/7/7-1.py index 5df477d..fa31462 100644 --- a/7/7-1.py +++ b/7/7-1.py @@ -2,11 +2,9 @@ CARD_STRENGTHS = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"] -HAND_STRENGTHS = [1, 2, [2, 2], 3, [2, 3], 4, 5] - def get_input(): - with open("seven.txt", "r") as f: + with open("7.txt", "r") as f: return [ {f.strip().split(" ")[0]: f.strip().split(" ")[1]} for f in f.readlines() ] diff --git a/7/7-2.py b/7/7-2.py index 29305d8..d63dd46 100644 --- a/7/7-2.py +++ b/7/7-2.py @@ -4,7 +4,7 @@ def get_input(): - with open("seven.txt", "r") as f: + with open("7.txt", "r") as f: return [ {f.strip().split(" ")[0]: f.strip().split(" ")[1]} for f in f.readlines() ] diff --git a/8/8-1.py b/8/8-1.py index 23b084e..5a93c90 100644 --- a/8/8-1.py +++ b/8/8-1.py @@ -2,7 +2,7 @@ def get_input(): - with open("eight.txt", "r") as f: + with open("8.txt", "r") as f: return [f.strip() for f in f.readlines()] diff --git a/8/8-2.py b/8/8-2.py index f1bf24e..51601aa 100644 --- a/8/8-2.py +++ b/8/8-2.py @@ -4,7 +4,7 @@ def get_input(): - with open("eight.txt", "r") as f: + with open("8.txt", "r") as f: return [f.strip() for f in f.readlines()] diff --git a/9/9-1.py b/9/9-1.py index fd41bd0..1e165b9 100644 --- a/9/9-1.py +++ b/9/9-1.py @@ -1,5 +1,5 @@ def get_input(): - with open("nine.txt", "r") as f: + with open("9.txt", "r") as f: return f.read().splitlines() diff --git a/9/9-2.py b/9/9-2.py index 54d35bf..251049f 100644 --- a/9/9-2.py +++ b/9/9-2.py @@ -1,5 +1,5 @@ def get_input(): - with open("nine.txt", "r") as f: + with open("9.txt", "r") as f: return f.read().splitlines()