Add solution for problem 7
This commit is contained in:
66
Problem7_1.py
Normal file
66
Problem7_1.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user