Files
AdventOfCode2025/Problem7_1.py
2025-12-07 12:03:56 -05:00

67 lines
1.7 KiB
Python

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