From 9170d0c97c9e7acbd07f842aa13ca7c50e2b4a3e Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Sun, 7 Dec 2025 12:03:56 -0500 Subject: [PATCH] Add solution for problem 7 --- Problem7_1.py | 66 +++++++++++++++++++++ Problem7_2.py | 84 +++++++++++++++++++++++++++ files/Problem7.txt | 142 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 Problem7_1.py create mode 100644 Problem7_2.py create mode 100644 files/Problem7.txt diff --git a/Problem7_1.py b/Problem7_1.py new file mode 100644 index 0000000..ee8ed20 --- /dev/null +++ b/Problem7_1.py @@ -0,0 +1,66 @@ +def start() : + location = tachyonManifold[0].find("S") + tachyonManifold[1] = tachyonManifold[1][0:location] + "|" + tachyonManifold[1][location + 1:] + +def registerSplits(row: int) : + numSplits = 0 + numExtensions = 0 + for cnt in range(len(tachyonManifold[row])) : + if row > 0 and tachyonManifold[row - 1][cnt] == "|": + if tachyonManifold[row][cnt] == "." : + tachyonManifold[row] = tachyonManifold[row][0:cnt] + "|" + tachyonManifold[row][cnt + 1:] + numExtensions += 1 + elif tachyonManifold[row][cnt] == "^": + if cnt > 0 and cnt + 1 < len(tachyonManifold[row]) : + tachyonManifold[row] = tachyonManifold[row][0:cnt - 1] + "|^|" + tachyonManifold[row][cnt + 2:] + elif cnt == 0 : + tachyonManifold[row] = "^|" + tachyonManifold[row][2:] + else : + tachyonManifold[row] = tachyonManifold[row][0:-2] + "|^" + numSplits += 1 + return numSplits + +def printManifold() -> int: + for line in tachyonManifold : + print(line) + print("\n") + +testInput = [ + ".......S.......", + "...............", + ".......^.......", + "...............", + "......^.^......", + "...............", + ".....^.^.^.....", + "...............", + "....^.^...^....", + "...............", + "...^.^...^.^...", + "...............", + "..^...^.....^..", + "...............", + ".^.^.^.^.^...^.", + "..............." +] + +def readFile() : + ary = [] + with open("files/Problem7.txt", "r") as file : + for line in file : + ary.append(line.replace("\n", "")) + return ary + +#tachyonManifold = testInput +tachyonManifold = readFile() +start() +#printManifold() +totalSplits = 0 +for row in range(1, len(tachyonManifold)) : + numberSplits = registerSplits(row) + totalSplits += numberSplits + #print(f"Row = {row}") + #printManifold() +print(f"Total splits = {totalSplits}") + +#Total splits = 1562 diff --git a/Problem7_2.py b/Problem7_2.py new file mode 100644 index 0000000..fe09ff7 --- /dev/null +++ b/Problem7_2.py @@ -0,0 +1,84 @@ +def start() : + location = tachyonManifold[0].find("S") + tachyonManifold[1] = tachyonManifold[1][0:location] + "|" + tachyonManifold[1][location + 1:] + accumulator[location] = 1 + +def registerSplits(row: int) : + numSplits = 0 + numExtensions = 0 + newAccumulator = [] + newManifold = tachyonManifold[row] + for cnt in range(len(accumulator)) : + newAccumulator.append(0) + for cnt in range(len(tachyonManifold[row])) : + char = tachyonManifold[row][cnt] + if row > 0 and tachyonManifold[row - 1][cnt] == "|": + if tachyonManifold[row][cnt] == "." : + newManifold = newManifold[0:cnt] + "|" + newManifold[cnt + 1:] + newAccumulator[cnt] += accumulator[cnt] + numExtensions += 1 + elif tachyonManifold[row][cnt] == "^": + if cnt > 0 and cnt + 1 < len(tachyonManifold[row]) : + newManifold = newManifold[0:cnt - 1] + "|^|" + newManifold[cnt + 2:] + newAccumulator[cnt - 1] += accumulator[cnt] + newAccumulator[cnt + 1] += accumulator[cnt] + elif cnt == 0 : + newManifold = "^|" + newManifold[2:] + newAccumulator[cnt + 1] += accumulator[cnt] + else : + newManifold = newManifold[0:-2] + "|^" + newAccumulator[cnt - 1] += accumulator[cnt] + numSplits += 1 + elif tachyonManifold[row][cnt] == "|" : + newAccumulator[cnt] = accumulator[cnt] + tachyonManifold[row] = newManifold + return numSplits, newAccumulator + +def printManifold() -> int: + for line in tachyonManifold : + print(line) + print("\n") + +testInput = [ + ".......S.......", + "...............", + ".......^.......", + "...............", + "......^.^......", + "...............", + ".....^.^.^.....", + "...............", + "....^.^...^....", + "...............", + "...^.^...^.^...", + "...............", + "..^...^.....^..", + "...............", + ".^.^.^.^.^...^.", + "..............." +] + +def readFile() : + ary = [] + with open("files/Problem7.txt", "r") as file : + for line in file : + ary.append(line.replace("\n", "")) + return ary + +#tachyonManifold = testInput +tachyonManifold = readFile() +accumulator: list[int] = [] +for cnt in range(len(tachyonManifold[0])) : + accumulator.append(0) +start() +#printManifold() +totalSplits = 0 +for row in range(1, len(tachyonManifold)) : + numberSplits, newAccumulator = registerSplits(row) + totalSplits += numberSplits + accumulator = newAccumulator + #print(f"Row = {row}") + #printManifold() +print(f"Total splits = {totalSplits}, Accumulator = {sum(accumulator)}") + +#Total splits = 1562, Accumulator = 24292631346665 diff --git a/files/Problem7.txt b/files/Problem7.txt new file mode 100644 index 0000000..e4f5ede --- /dev/null +++ b/files/Problem7.txt @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.....^................................................................... +............................................................................................................................................. +..................................................................^.^.^.^.^.................................................................. +............................................................................................................................................. +.................................................................^.^...^...^................................................................. +............................................................................................................................................. +................................................................^.^.^.^.^.^.^................................................................ +............................................................................................................................................. +...............................................................^.^.^.....^.^.^............................................................... +............................................................................................................................................. +..............................................................^.^.^.^...^.^.^.^.............................................................. +............................................................................................................................................. +.............................................................^.^.^.^.......^.^.^............................................................. +............................................................................................................................................. +............................................................^.^.^...^.^...^.^.^.^............................................................ +............................................................................................................................................. +...........................................................^.^.^...^.^...^.^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^...^.....^.^.^.^.^.^...^.......................................................... +............................................................................................................................................. +.........................................................^.^.......^.^...^.^.^...^.^......................................................... +............................................................................................................................................. +........................................................^.^.^.^.^...^.....^.^.....^.^........................................................ +............................................................................................................................................. +.......................................................^.^.^.^.^.^...^.^.....^.^...^.^....................................................... +............................................................................................................................................. +......................................................^.^.^...^...^...^...^.^.^.^.^.^.^...................................................... +............................................................................................................................................. +.....................................................^.^...^...^...^.^.^.^.^.^...^.^...^..................................................... +............................................................................................................................................. +....................................................^.^.^.....^.^.........^...^.^.^.....^.................................................... +............................................................................................................................................. +...................................................^...^.^.^.....^.^.^...^...^.....^.^.^.^................................................... +............................................................................................................................................. +..................................................^.^.^.^.^.^.^...^.^.^...^...^.......^...^.................................................. +............................................................................................................................................. +.................................................^...^.....^.^.^.^.....^.^...^.....^.^.^...^................................................. +............................................................................................................................................. +................................................^...^.....^.^.^.^.^.^.^.^.^.^.............^.^................................................ +............................................................................................................................................. +...............................................^.^.^.....^.^.....^.^.^.^.^.....^.....^...^.^.^............................................... +............................................................................................................................................. +..............................................^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^.^...^.............................................. +............................................................................................................................................. +.............................................^.^.^...^.^.^...^...^.^.^.....^...^.....^.^.^...^.^............................................. +............................................................................................................................................. +............................................^.^.......^.^.^.^.....^.......^.^.^...^.^.........^.^............................................ +............................................................................................................................................. +...........................................^...^...^...^...^.^.........^.^...^.^.....^.....^.^.^.^........................................... +............................................................................................................................................. +..........................................^...^.^...^.^.^.^.^...^.^.^.^.^.^.....^...^...^.^.^.^.^.^.......................................... +............................................................................................................................................. +.........................................^.^...^.^...^.^.....^.^.......^.^.....^.^.^.^.^.^...^.^.^.^......................................... +............................................................................................................................................. +........................................^.^...^.^...^.^.......^.......^.^.^.^.^.^.^.......^.^.^...^.^........................................ +............................................................................................................................................. +.......................................^.^.^...^.^...^.^...^.^...^.....^.^.^...^.......^...^.^.^.^.^.^....................................... +............................................................................................................................................. +......................................^.....^.^.....^.....^...^...^.^.^...^.^.^.^.....^.^.^...^.^.^...^...................................... +............................................................................................................................................. +.....................................^.^.....^.^.^...^.....^.^.^.^...^.^.......^.^...^.^.^...^.^.^.^.^.^..................................... +............................................................................................................................................. +....................................^.^.^.^...^.......^.^...^...^.....^...^...^.^...^.^.^.......^.^.^...^.................................... +............................................................................................................................................. +...................................^.^.....^.....^.^.^.^.^.^...^.^.^.^.^.^.....^.^...^.^...^.^.^...^.....^................................... +............................................................................................................................................. +..................................^...^...^.^.^...^.^.^.....^.^.^.....^.^.^.^.^.^.^.^.......^.^...^.^.^.^.^.................................. +............................................................................................................................................. +.................................^.^...^.^.^.^.^...^.^...^.^.^.^.......^.^.^.^.^...^...^.^.^.^.^.^.^.......^................................. +............................................................................................................................................. +................................^...^.^.^...^.^.^.^.^...^.^.^...^...^.^...^.^.......^.^.^.^.^.....^.^.^.^.^.^................................ +............................................................................................................................................. +...............................^.^.^.^.^...^.^.^.....^.^...^...^.^...^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^............................... +............................................................................................................................................. +..............................^.^.^.....^...^.^.^.^...^...^.^.^.^.^.^.^...^.^.^.......^...^.^.^.^.^.^...^.^.^.^.............................. +............................................................................................................................................. +.............................^.....^.^...^.^.^.^...^.^.^.^...^...^...^.^.^.^.....^.^.......^...^.^...^.^.^.^...^............................. +............................................................................................................................................. +............................^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.......^.^.^...^.^...^.....^............................ +............................................................................................................................................. +...........................^.^...^...^...^.^.^.^...^.....^...^.^.^.^.^.^.^...^.......^.^.^.^.^...^...^.......^.^.^........................... +............................................................................................................................................. +..........................^.....^...^.^.^.....^.^.^...^...^...^.....^...^...^.^.^.^.^.^.^.^.^.....^...^.^.^.......^.......................... +............................................................................................................................................. +.........................^.^.^...^.^.....^.^...^.^.^...^.....^.^.^.^.....^...^...^.^.^...^.^...^.....^.^.^.^.....^.^......................... +............................................................................................................................................. +........................^...^.^.^.^.^.......^.^.^.......^.^.^...^.^.....^.^.^.^.^...^.^.^.......^.^.^.........^.^.^.^........................ +............................................................................................................................................. +.......................^.^.^.^.^.....^.^...^.^.^...^.^.^.^...^.^...^...^...^.....^.^.^.^...^.^.^.^...^.......^.^.^.^.^....................... +............................................................................................................................................. +......................^.^.^.^.^.^.....^.^.......^.^.^...^.^.^.^.^.^...^.^.^.^...^.^...^...^.......^.^.^.^...^.^.^.^...^...................... +............................................................................................................................................. +.....................^.^.^.^...^.^.^.^.^.^.^...^...^.^.^.....^.^.^...^.^.^.....^.^.^.....^...^.^.^.^.^.^.^.^.^.^...^...^..................... +............................................................................................................................................. +....................^.^...^.^.^.^...^...^.........^.^...^...^...^...^.^...^.^.^...^...^...^...^.^.^.^.^.^.^...^.^.^.....^.................... +............................................................................................................................................. +...................^.^.^...^...^...^.^.^...^.^.^...^.....^.^.^.^.....^.^...^...^.^...^...^.^.^.^.^.^...^.^.^.^...^.....^.^................... +............................................................................................................................................. +..................^.^.......^.^.^...^.^.^...^.^.....^.^.^.^.^.^.^.^.....^...^.^.^.........^.............^.......^...^.^.^.^.................. +............................................................................................................................................. +.................^.^.........^...^.^.......^.^.^.^.^.^.^.^.^...^.....^.^.^.^.........^.^.^.^.^.....^...^...^.^.^.^.^...^...^................. +............................................................................................................................................. +................^.^.^...^.^.^.....^.^.^...^.^.^.^...^...^.^...^.^.^.^.^.^...^.^...^.^.^.....^...^.^...^...^.^...^.^.^.....^.^................ +............................................................................................................................................. +...............^.^.^.^.^.^.^.^.....^...^.^.^.^.^...^.........^.^.^.^...^.^.^.....^...^...^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^............... +............................................................................................................................................. +..............^.^.^...^.^.^.^...^.^...^.^.^.^.^.^.^.^.^.^...^.^...^.....^.^...^.............^.^...^.^.^.^.^...^.^.^.^.....^.^.^.............. +............................................................................................................................................. +.............^.^.^.^.....^...^...^.....^.^...^...^.......^...^...^.^...^...^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^...^...^.^.^.....^............. +............................................................................................................................................. +............^...^.^.^.^.^...^...^.^.^.....^.^.^.^...^.^...^...^...^...^.^.......^.^.^.....^...^...^.^.^.^.^.^.......^.^.^...^.^.^............ +............................................................................................................................................. +...........^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.......^.^.^...^.^.^.^.^.^.^.^...^.^...^.........^.^.^.^.....^...^.^...^.^.^.^.....^.^........... +............................................................................................................................................. +..........^.....^.^.^.....^.....^.....^.^.^.^.^.^.^.^.^.....^.^.^.^.^...^.^.^...^.......^.^...^...^...^.....^...^.^.^.^.^.^.^.^.^.^.......... +............................................................................................................................................. +.........^...^...^.^.^.....^.^.^.^.^.^...^...^...^...^.......^.^.^.^.^.^.^...^.^.^.^.^.^.........^...^.^.^...^.^.....^.^.^.^.^.....^......... +............................................................................................................................................. +........^.^.....^.^.^.^...^.^.^.^...^.^.^.^.^.^...^.^.^...^.^.^.^...^...^...^.........^.^.^.^.^.....^.^.^...^.^.^.^.^...^...^.^.^...^........ +............................................................................................................................................. +.......^.^.^.^.^.^.^.......^.^.........^.^.^.^.^.^.^.^.^.^.^...^...^.^...^...^...^...^...^.^.....^...^...^...^.^.^.....^...^...^.....^....... +............................................................................................................................................. +......^.^.^...^.^.^.^.^.^.^.......^.^.^.^.^.^.^.^.....^.....^.....^.^.^.^.^.^.^.^...^.^.^.^.^.^...^.^.^.......^.^.....^.^.^.^.....^.^.^...... +............................................................................................................................................. +.....^...^.^.^.^.....^...^...^.....^.^.^.^.^.^.^.....^.^.^...^...^.^.^.^.^.^...^...^.^.^.^.....^.^.^.^...^.....^.^...^...^.^...^.^.^.^.^..... +............................................................................................................................................. +....^.^.^...^.^.^.^.^.^...^...^.^.^.^.^...^.^.^.^...^...^.^...^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.^.^...^.......^...^.....^.... +............................................................................................................................................. +...^.^.^.....^.^.^.^.^.....^...^.....^...^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^...^.^.^.....^.....^...^.^.^.^.^...^.^...^...^.^...^.^.^.^.^... +............................................................................................................................................. +..^.^.......^.^.^.^...^...^.^.....^.^.^.^.^.^...^.^.....^...^.^.....^.^...^.^.^...^...^.^.^.^.....^.^.^...^...^...^.^.^.^...^.^.^...^.^...^.. +............................................................................................................................................. +.^.^...^.^.^...^...^...^.^.....^.^.....^.^.^.^...^.....^.^.^.^...^.^.^.^.^.^...^.^.^.....^.^.^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^.^.....^.^. +............................................................................................................................................. \ No newline at end of file