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