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
|
||||
84
Problem7_2.py
Normal file
84
Problem7_2.py
Normal file
@@ -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
|
||||
142
files/Problem7.txt
Normal file
142
files/Problem7.txt
Normal file
@@ -0,0 +1,142 @@
|
||||
......................................................................S......................................................................
|
||||
.............................................................................................................................................
|
||||
......................................................................^......................................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................................^.^.....................................................................
|
||||
.............................................................................................................................................
|
||||
....................................................................^.^.^....................................................................
|
||||
.............................................................................................................................................
|
||||
...................................................................^.....^...................................................................
|
||||
.............................................................................................................................................
|
||||
..................................................................^.^.^.^.^..................................................................
|
||||
.............................................................................................................................................
|
||||
.................................................................^.^...^...^.................................................................
|
||||
.............................................................................................................................................
|
||||
................................................................^.^.^.^.^.^.^................................................................
|
||||
.............................................................................................................................................
|
||||
...............................................................^.^.^.....^.^.^...............................................................
|
||||
.............................................................................................................................................
|
||||
..............................................................^.^.^.^...^.^.^.^..............................................................
|
||||
.............................................................................................................................................
|
||||
.............................................................^.^.^.^.......^.^.^.............................................................
|
||||
.............................................................................................................................................
|
||||
............................................................^.^.^...^.^...^.^.^.^............................................................
|
||||
.............................................................................................................................................
|
||||
...........................................................^.^.^...^.^...^.^.^.^.^...........................................................
|
||||
.............................................................................................................................................
|
||||
..........................................................^...^.....^.^.^.^.^.^...^..........................................................
|
||||
.............................................................................................................................................
|
||||
.........................................................^.^.......^.^...^.^.^...^.^.........................................................
|
||||
.............................................................................................................................................
|
||||
........................................................^.^.^.^.^...^.....^.^.....^.^........................................................
|
||||
.............................................................................................................................................
|
||||
.......................................................^.^.^.^.^.^...^.^.....^.^...^.^.......................................................
|
||||
.............................................................................................................................................
|
||||
......................................................^.^.^...^...^...^...^.^.^.^.^.^.^......................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................^.^...^...^...^.^.^.^.^.^...^.^...^.....................................................
|
||||
.............................................................................................................................................
|
||||
....................................................^.^.^.....^.^.........^...^.^.^.....^....................................................
|
||||
.............................................................................................................................................
|
||||
...................................................^...^.^.^.....^.^.^...^...^.....^.^.^.^...................................................
|
||||
.............................................................................................................................................
|
||||
..................................................^.^.^.^.^.^.^...^.^.^...^...^.......^...^..................................................
|
||||
.............................................................................................................................................
|
||||
.................................................^...^.....^.^.^.^.....^.^...^.....^.^.^...^.................................................
|
||||
.............................................................................................................................................
|
||||
................................................^...^.....^.^.^.^.^.^.^.^.^.^.............^.^................................................
|
||||
.............................................................................................................................................
|
||||
...............................................^.^.^.....^.^.....^.^.^.^.^.....^.....^...^.^.^...............................................
|
||||
.............................................................................................................................................
|
||||
..............................................^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^.^...^..............................................
|
||||
.............................................................................................................................................
|
||||
.............................................^.^.^...^.^.^...^...^.^.^.....^...^.....^.^.^...^.^.............................................
|
||||
.............................................................................................................................................
|
||||
............................................^.^.......^.^.^.^.....^.......^.^.^...^.^.........^.^............................................
|
||||
.............................................................................................................................................
|
||||
...........................................^...^...^...^...^.^.........^.^...^.^.....^.....^.^.^.^...........................................
|
||||
.............................................................................................................................................
|
||||
..........................................^...^.^...^.^.^.^.^...^.^.^.^.^.^.....^...^...^.^.^.^.^.^..........................................
|
||||
.............................................................................................................................................
|
||||
.........................................^.^...^.^...^.^.....^.^.......^.^.....^.^.^.^.^.^...^.^.^.^.........................................
|
||||
.............................................................................................................................................
|
||||
........................................^.^...^.^...^.^.......^.......^.^.^.^.^.^.^.......^.^.^...^.^........................................
|
||||
.............................................................................................................................................
|
||||
.......................................^.^.^...^.^...^.^...^.^...^.....^.^.^...^.......^...^.^.^.^.^.^.......................................
|
||||
.............................................................................................................................................
|
||||
......................................^.....^.^.....^.....^...^...^.^.^...^.^.^.^.....^.^.^...^.^.^...^......................................
|
||||
.............................................................................................................................................
|
||||
.....................................^.^.....^.^.^...^.....^.^.^.^...^.^.......^.^...^.^.^...^.^.^.^.^.^.....................................
|
||||
.............................................................................................................................................
|
||||
....................................^.^.^.^...^.......^.^...^...^.....^...^...^.^...^.^.^.......^.^.^...^....................................
|
||||
.............................................................................................................................................
|
||||
...................................^.^.....^.....^.^.^.^.^.^...^.^.^.^.^.^.....^.^...^.^...^.^.^...^.....^...................................
|
||||
.............................................................................................................................................
|
||||
..................................^...^...^.^.^...^.^.^.....^.^.^.....^.^.^.^.^.^.^.^.......^.^...^.^.^.^.^..................................
|
||||
.............................................................................................................................................
|
||||
.................................^.^...^.^.^.^.^...^.^...^.^.^.^.......^.^.^.^.^...^...^.^.^.^.^.^.^.......^.................................
|
||||
.............................................................................................................................................
|
||||
................................^...^.^.^...^.^.^.^.^...^.^.^...^...^.^...^.^.......^.^.^.^.^.....^.^.^.^.^.^................................
|
||||
.............................................................................................................................................
|
||||
...............................^.^.^.^.^...^.^.^.....^.^...^...^.^...^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^...............................
|
||||
.............................................................................................................................................
|
||||
..............................^.^.^.....^...^.^.^.^...^...^.^.^.^.^.^.^...^.^.^.......^...^.^.^.^.^.^...^.^.^.^..............................
|
||||
.............................................................................................................................................
|
||||
.............................^.....^.^...^.^.^.^...^.^.^.^...^...^...^.^.^.^.....^.^.......^...^.^...^.^.^.^...^.............................
|
||||
.............................................................................................................................................
|
||||
............................^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.......^.^.^...^.^...^.....^............................
|
||||
.............................................................................................................................................
|
||||
...........................^.^...^...^...^.^.^.^...^.....^...^.^.^.^.^.^.^...^.......^.^.^.^.^...^...^.......^.^.^...........................
|
||||
.............................................................................................................................................
|
||||
..........................^.....^...^.^.^.....^.^.^...^...^...^.....^...^...^.^.^.^.^.^.^.^.^.....^...^.^.^.......^..........................
|
||||
.............................................................................................................................................
|
||||
.........................^.^.^...^.^.....^.^...^.^.^...^.....^.^.^.^.....^...^...^.^.^...^.^...^.....^.^.^.^.....^.^.........................
|
||||
.............................................................................................................................................
|
||||
........................^...^.^.^.^.^.......^.^.^.......^.^.^...^.^.....^.^.^.^.^...^.^.^.......^.^.^.........^.^.^.^........................
|
||||
.............................................................................................................................................
|
||||
.......................^.^.^.^.^.....^.^...^.^.^...^.^.^.^...^.^...^...^...^.....^.^.^.^...^.^.^.^...^.......^.^.^.^.^.......................
|
||||
.............................................................................................................................................
|
||||
......................^.^.^.^.^.^.....^.^.......^.^.^...^.^.^.^.^.^...^.^.^.^...^.^...^...^.......^.^.^.^...^.^.^.^...^......................
|
||||
.............................................................................................................................................
|
||||
.....................^.^.^.^...^.^.^.^.^.^.^...^...^.^.^.....^.^.^...^.^.^.....^.^.^.....^...^.^.^.^.^.^.^.^.^.^...^...^.....................
|
||||
.............................................................................................................................................
|
||||
....................^.^...^.^.^.^...^...^.........^.^...^...^...^...^.^...^.^.^...^...^...^...^.^.^.^.^.^.^...^.^.^.....^....................
|
||||
.............................................................................................................................................
|
||||
...................^.^.^...^...^...^.^.^...^.^.^...^.....^.^.^.^.....^.^...^...^.^...^...^.^.^.^.^.^...^.^.^.^...^.....^.^...................
|
||||
.............................................................................................................................................
|
||||
..................^.^.......^.^.^...^.^.^...^.^.....^.^.^.^.^.^.^.^.....^...^.^.^.........^.............^.......^...^.^.^.^..................
|
||||
.............................................................................................................................................
|
||||
.................^.^.........^...^.^.......^.^.^.^.^.^.^.^.^...^.....^.^.^.^.........^.^.^.^.^.....^...^...^.^.^.^.^...^...^.................
|
||||
.............................................................................................................................................
|
||||
................^.^.^...^.^.^.....^.^.^...^.^.^.^...^...^.^...^.^.^.^.^.^...^.^...^.^.^.....^...^.^...^...^.^...^.^.^.....^.^................
|
||||
.............................................................................................................................................
|
||||
...............^.^.^.^.^.^.^.^.....^...^.^.^.^.^...^.........^.^.^.^...^.^.^.....^...^...^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^...............
|
||||
.............................................................................................................................................
|
||||
..............^.^.^...^.^.^.^...^.^...^.^.^.^.^.^.^.^.^.^...^.^...^.....^.^...^.............^.^...^.^.^.^.^...^.^.^.^.....^.^.^..............
|
||||
.............................................................................................................................................
|
||||
.............^.^.^.^.....^...^...^.....^.^...^...^.......^...^...^.^...^...^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^...^...^.^.^.....^.............
|
||||
.............................................................................................................................................
|
||||
............^...^.^.^.^.^...^...^.^.^.....^.^.^.^...^.^...^...^...^...^.^.......^.^.^.....^...^...^.^.^.^.^.^.......^.^.^...^.^.^............
|
||||
.............................................................................................................................................
|
||||
...........^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.......^.^.^...^.^.^.^.^.^.^.^...^.^...^.........^.^.^.^.....^...^.^...^.^.^.^.....^.^...........
|
||||
.............................................................................................................................................
|
||||
..........^.....^.^.^.....^.....^.....^.^.^.^.^.^.^.^.^.....^.^.^.^.^...^.^.^...^.......^.^...^...^...^.....^...^.^.^.^.^.^.^.^.^.^..........
|
||||
.............................................................................................................................................
|
||||
.........^...^...^.^.^.....^.^.^.^.^.^...^...^...^...^.......^.^.^.^.^.^.^...^.^.^.^.^.^.........^...^.^.^...^.^.....^.^.^.^.^.....^.........
|
||||
.............................................................................................................................................
|
||||
........^.^.....^.^.^.^...^.^.^.^...^.^.^.^.^.^...^.^.^...^.^.^.^...^...^...^.........^.^.^.^.^.....^.^.^...^.^.^.^.^...^...^.^.^...^........
|
||||
.............................................................................................................................................
|
||||
.......^.^.^.^.^.^.^.......^.^.........^.^.^.^.^.^.^.^.^.^.^...^...^.^...^...^...^...^...^.^.....^...^...^...^.^.^.....^...^...^.....^.......
|
||||
.............................................................................................................................................
|
||||
......^.^.^...^.^.^.^.^.^.^.......^.^.^.^.^.^.^.^.....^.....^.....^.^.^.^.^.^.^.^...^.^.^.^.^.^...^.^.^.......^.^.....^.^.^.^.....^.^.^......
|
||||
.............................................................................................................................................
|
||||
.....^...^.^.^.^.....^...^...^.....^.^.^.^.^.^.^.....^.^.^...^...^.^.^.^.^.^...^...^.^.^.^.....^.^.^.^...^.....^.^...^...^.^...^.^.^.^.^.....
|
||||
.............................................................................................................................................
|
||||
....^.^.^...^.^.^.^.^.^...^...^.^.^.^.^...^.^.^.^...^...^.^...^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.^.^...^.......^...^.....^....
|
||||
.............................................................................................................................................
|
||||
...^.^.^.....^.^.^.^.^.....^...^.....^...^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^...^.^.^.....^.....^...^.^.^.^.^...^.^...^...^.^...^.^.^.^.^...
|
||||
.............................................................................................................................................
|
||||
..^.^.......^.^.^.^...^...^.^.....^.^.^.^.^.^...^.^.....^...^.^.....^.^...^.^.^...^...^.^.^.^.....^.^.^...^...^...^.^.^.^...^.^.^...^.^...^..
|
||||
.............................................................................................................................................
|
||||
.^.^...^.^.^...^...^...^.^.....^.^.....^.^.^.^...^.....^.^.^.^...^.^.^.^.^.^...^.^.^.....^.^.^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^.^.....^.^.
|
||||
.............................................................................................................................................
|
||||
Reference in New Issue
Block a user