7 день
This commit is contained in:
60
2025/day07/part1.py
Normal file
60
2025/day07/part1.py
Normal file
@@ -0,0 +1,60 @@
|
||||
input = """.......S.......
|
||||
...............
|
||||
.......^.......
|
||||
...............
|
||||
......^.^......
|
||||
...............
|
||||
.....^.^.^.....
|
||||
...............
|
||||
....^.^...^....
|
||||
...............
|
||||
...^.^...^.^...
|
||||
...............
|
||||
..^...^.....^..
|
||||
...............
|
||||
.^.^.^.^.^...^.
|
||||
..............."""
|
||||
|
||||
# with open("input.txt", "r") as file:
|
||||
# input = file.read()
|
||||
|
||||
|
||||
start = [row.find("S") for row in input.splitlines()][0]
|
||||
|
||||
temp = [list(map(str, row)) for row in input.splitlines()]
|
||||
list_temp = [[] for _ in range(len(input.splitlines()))]
|
||||
for i, row in enumerate(temp[1:]):
|
||||
for ii, r in enumerate(row):
|
||||
if r == "^":
|
||||
list_temp[i+1].append(ii)
|
||||
|
||||
print(list_temp)
|
||||
for i, *row in enumerate(zip(temp, list_temp)):
|
||||
print(i-1, temp[i-1], "прошлая строка")
|
||||
print(i, row[0][0], "сейчас", row[0][1])
|
||||
if i == 0:
|
||||
if temp[i+1][start] != "^":
|
||||
temp[i+1][start] = "|"
|
||||
else:
|
||||
if row[0][1]:
|
||||
print(f"строка {i}, {row[0][1]}")
|
||||
for y in row[0][1]:
|
||||
temp[i][y-1] = "|"
|
||||
temp[i][y+1] = "|"
|
||||
elif "^" not in row[0][0] and row[0][1] == []:
|
||||
for ii, y in enumerate(row[0][0]):
|
||||
if temp[i-1][ii] == "|":
|
||||
temp[i][ii] = "|"
|
||||
for iii, y in enumerate(row[0][0]):
|
||||
if temp[i-1][iii] == "|" and temp[i][iii] != "^":
|
||||
temp[i][iii] = "|"
|
||||
|
||||
print("="*100)
|
||||
|
||||
|
||||
|
||||
count = 0
|
||||
for i, row in enumerate(temp):
|
||||
print(row)
|
||||
count += sum(1 for y, r in enumerate(row) if r == "^" and temp[i-1][y] == "|")
|
||||
print(count)
|
||||
Reference in New Issue
Block a user