7 день
This commit is contained in:
@@ -2,8 +2,8 @@ input = """123 328 51 64
|
|||||||
45 64 387 23
|
45 64 387 23
|
||||||
6 98 215 314
|
6 98 215 314
|
||||||
* + * + """
|
* + * + """
|
||||||
with open("input.txt", "r") as file:
|
# with open("input.txt", "r") as file:
|
||||||
input = file.read()
|
# input = file.read()
|
||||||
# for row in input.splitlines():
|
# for row in input.splitlines():
|
||||||
# print(row)
|
# print(row)
|
||||||
# print("="*100)
|
# print("="*100)
|
||||||
|
|||||||
142
2025/day07/input.txt
Normal file
142
2025/day07/input.txt
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
......................................................................S......................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................................................^......................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................................................^.^.....................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................................................^...^....................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................................................^.^.^.^...................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................................................^...^.^.^..................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................................................^.^.^.^.^.^.................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................................................^.^...^.^.^.^................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................................................^.^.^...^...^.^...............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................................................^.^...^.^.^.^...^..............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................................................^.....^...^.^.^.^.^.............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................................................^.^.^.^.^...^.^.^...^............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................................................^.....^.^.^.^...^...^.^...........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................................................^.^...^.......^.^.^.^.^.^..........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................................................^.^.^.^.^.^.^.^.^.^...^.^.^.........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................................................^.......^.^.^.^...^.^...^.^.^........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................................................^.^.^.^...^.^...^...^...^...^.^.......................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................................^.^...^.^.^.^...^.....^.^.^.^.^.^......................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................................^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.....................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................................^.^.^...^.^.^.^...^.^...^.^...^...^.^....................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................................^.^.^.^.^.......^.^.^.^.^.^...^.^...^.^...................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................................^.......^...^.^.^...^.....^.^.........^.^..................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................................^.^.^.^.^.^.^.^.^.^.^...^...^...^.^.....^.^.................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................................^...^.^...^.^.^.......^.....^...^...^.....^.^................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................................^.^.^...^.^...^...^.....^...^.^.^.^.^...^.^.^.^...............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................................^.......^.^.^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^..............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................................^.^...^.^.^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^.............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................................^.^.^.^.....^...^.....^.^.^.^...^.^.^.^...^...^.^.^.^............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................................^.....^.^.^.......^.....^.^...^.^.^.^.^.^.^.^...^.^.^.^...........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................................^.^.^.^.^.^...^.^.^.....^.^.....^...^.^.^.^.....^.^.^...^..........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................................^.^.^.^...............^.^.^...^.^.........^.^.^...^.^...^.^.........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^...^.^.....^.^.^.^........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................................^...^.^.^.^.^.^.^.^...^...^.^.^.......^.^.^.^.^.^.........^...^.......................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................^.^.^.^.^.^...^.^.^.......^.....^...^.^.......^.^...^.^.^...^...^......................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................^.^.^.^.^.....^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.....................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^.^.^...^.^.^.^...^.^...^...^....................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................^.^.^...^.^.^.^.^.^.......^.^.^.^.^...^.^.^.^.^.^.^.^...^.^...^.....^.^...................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................^.^...^.......^.^.^.^...^...^.^.....^.......^.^.^...^...^.^.^.^.^.^.^.^.^..................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................^.^.....^...^.^.^...^...^.^.^.......^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^.^.................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................^.....^.^.^...^.^...^...^...^.^.^.^...^.^.^.^...^.^...^.^.^.^...^.^.^...^...^................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................^.^.^.^.^.......^...^.^...^...^.^.^.^.^.^...^.^.^.....^.^.^.^.^.......^.....^.^...............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................^...^...^.....^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^.^...^...^.^.^.........^.^.^..............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................^.^.....^.....^...^.^.^.^...^.....^...^.^.^...^...^.^...^.^...^.^.^.^.^.^.^...^...^.............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................^.^.^...^.^...^.^.^...^.^.^...^.^.^.^.....^...^.^.^.^.....^.^.^...^.^.^.^.^.^.^.^...^............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................^.^.^.......^.^.^.^.^...^.^.^.^.^...^.....^.^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^...^.^...........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................^.^.....^...^.^.^...^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.^.^...^...^.^...^.^.^...^.^.^..........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................^.^...^.^.^...^.^.^.^.^...^.^...^.............^.^.^.^.......^.^.^.^.^...^.^.^...^.^.^.^.^.^.........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................^.^.........^.^.^.^.^.^...^.......^...^.^.^...^.^.^.....^.^.^.......^.....^.^.^.^.^.^.^.^.^.^........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.....^.^...^.^.^.^...^.^.^.^.......................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................^.^.^.^.......^.^.^...^.^...^.^...^...^.^...^...^.....^.^...^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^.^......................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................^.^.^.^...^...^...^.^.^.....^.^.^.^...^...^.^.^.^.^.........^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^.....................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................^.^.^...^...^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.....^...^.^.^.^.......^...^.^.^.^.^.^...^.^.^...^.^...^....................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................^.^...^.^.^.^.^...^.^.^.^...^.^.^.^.^.^...^.^...^...^.^.^.^.......^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^...................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................^.^.^.^...^.....^.^...^...^.....^.....^.^...^...^...^.^.......^.........^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^..................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^.^.....^.^...^.....^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................^.......^.^.^.^...^.^...^.^.^.^.^.^.^.......^.^.^.^.^.....^.^.^.^.^.^.....^.^.^...^...^.^.^...^.^.....^.^.^.^................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............^.^.^.^.^.^.......^.^.^.......^.^.^...^.^.....^.^.........^.........^.^...^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^...............
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............^.^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.^...^.^...^...^.^.^...^.^.^...^...^...^.^.^.^.^.^.^.........^.^.^.^.^.^.^..............
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............^.^.^.^.^.....^.^...^.^.^.....^.^.....^...^.^.....^.^.^...^.^.^.^...^...^.....^.^.^...^...^.^.....^.....^.....^...^.............
|
||||||
|
.............................................................................................................................................
|
||||||
|
............^.^.....^.^.^.^.^.^.^.^.^.....^...^.^.....^.^.^.^.^...^...^.^.^.^.^.^.^...^...^.....^.........^.....^.^.^.^.^.^...^.^............
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........^.^...^.^.^.^...^.......^...^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.......^.^...^...........
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........^...^.^.^.^.........^.^.^.^.^...^.^.^.^...^.^.^.^.^.^.....^...^...^...^.^.^.^...^...^...^...^...^.......^...^...^.^...^.^..........
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........^...^.^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^...^.^...^.....^.^.....^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^.........
|
||||||
|
.............................................................................................................................................
|
||||||
|
........^.^...^.......^...^...^...^...^.........^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^...^.^...^.^...^.^.....^........
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......^...^.^.....^.^.^.^.^.^.^...^...^.^.^.^.....^.^.^...^.^.^...^.^...^...^.^.^.^.^.^.^.^...^.^.^.^.^.....^.^.^.^...^.^.^.^.^.^.^.^.......
|
||||||
|
.............................................................................................................................................
|
||||||
|
......^.^.^.........^.^.^...^...^.^...^.^.^.^...^.^...^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^.^......
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....^.^.....^.^...^.^.^...^...^.^.^.........^.^.^...^.^...^.^.^.^.^.^.^...^...^.^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.....^.....
|
||||||
|
.............................................................................................................................................
|
||||||
|
....^.^.^.....^...^.^.^.^.....^.....^...^.......^.^...^...^...^.^.^.^.^.....^.^.....^.^...^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^...^....
|
||||||
|
.............................................................................................................................................
|
||||||
|
...^.^...^.^...^.^.^.^...^.^.......^.^.^.^.^...^...^.^...^...^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^.^...^...
|
||||||
|
.............................................................................................................................................
|
||||||
|
..^.^.^.^.^.....^...^.^.^.^...^.^...^...^.^.^.^...^...^...^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^...^...^...^..
|
||||||
|
.............................................................................................................................................
|
||||||
|
.^.^...^.^.^...^.....^.^.^...^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^...^...^.^.^.....^.^...^...^.^.^.^.^.^.^.^.
|
||||||
|
.............................................................................................................................................
|
||||||
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)
|
||||||
55
2025/day07/part2.py
Normal file
55
2025/day07/part2.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# input = """.......S.......
|
||||||
|
# ...............
|
||||||
|
# .......^.......
|
||||||
|
# ...............
|
||||||
|
# ......^.^......
|
||||||
|
# ...............
|
||||||
|
# .....^.^.^.....
|
||||||
|
# ...............
|
||||||
|
# ....^.^...^....
|
||||||
|
# ...............
|
||||||
|
# ...^.^...^.^...
|
||||||
|
# ...............
|
||||||
|
# ..^...^.....^..
|
||||||
|
# ...............
|
||||||
|
# .^.^.^.^.^...^.
|
||||||
|
# ..............."""
|
||||||
|
|
||||||
|
with open("input.txt", "r") as file:
|
||||||
|
input = file.read()
|
||||||
|
|
||||||
|
|
||||||
|
def count_timelines(grid: str) -> int:
|
||||||
|
lines = grid.splitlines()
|
||||||
|
H = len(lines)
|
||||||
|
W = len(lines[0])
|
||||||
|
|
||||||
|
# стартовая колонка S
|
||||||
|
s_col = lines[0].index("S")
|
||||||
|
|
||||||
|
counts = [0] * W
|
||||||
|
counts[s_col] = 1 # одна частица -> один таймлайн в старте
|
||||||
|
|
||||||
|
for i in range(1, H):
|
||||||
|
new = [0] * W
|
||||||
|
row = lines[i]
|
||||||
|
for j, cell in enumerate(row):
|
||||||
|
k = counts[j]
|
||||||
|
if k == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if cell == "^":
|
||||||
|
# splitter: поток не проходит вниз, а расходится влево/вправо
|
||||||
|
if j - 1 >= 0:
|
||||||
|
new[j - 1] += k
|
||||||
|
if j + 1 < W:
|
||||||
|
new[j + 1] += k
|
||||||
|
else:
|
||||||
|
# пусто: идем прямо вниз
|
||||||
|
new[j] += k
|
||||||
|
|
||||||
|
counts = new
|
||||||
|
|
||||||
|
return sum(counts)
|
||||||
|
|
||||||
|
print(count_timelines(input))
|
||||||
Reference in New Issue
Block a user