From 70f0364674b09b1cfc8db290857edbd5fc9cbadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AE=D1=80=D0=B8=D0=B9=20=D0=A7=D0=B5=D1=80=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BA=D0=BE?= Date: Thu, 18 Dec 2025 14:44:33 +0300 Subject: [PATCH] =?UTF-8?q?7=20=D0=B4=D0=B5=D0=BD=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2025/day06/part1.py | 4 +- 2025/day07/input.txt | 142 +++++++++++++++++++++++++++++++++++++++++++ 2025/day07/part1.py | 60 ++++++++++++++++++ 2025/day07/part2.py | 55 +++++++++++++++++ 4 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 2025/day07/input.txt create mode 100644 2025/day07/part1.py create mode 100644 2025/day07/part2.py diff --git a/2025/day06/part1.py b/2025/day06/part1.py index 7a0b9d6..d76271e 100644 --- a/2025/day06/part1.py +++ b/2025/day06/part1.py @@ -2,8 +2,8 @@ input = """123 328 51 64 45 64 387 23 6 98 215 314 * + * + """ -with open("input.txt", "r") as file: - input = file.read() +# with open("input.txt", "r") as file: +# input = file.read() # for row in input.splitlines(): # print(row) # print("="*100) diff --git a/2025/day07/input.txt b/2025/day07/input.txt new file mode 100644 index 0000000..a33dba5 --- /dev/null +++ b/2025/day07/input.txt @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^...^.................................................................... +............................................................................................................................................. +...................................................................^.^.^.^................................................................... +............................................................................................................................................. +..................................................................^...^.^.^.................................................................. +............................................................................................................................................. +.................................................................^.^.^.^.^.^................................................................. +............................................................................................................................................. +................................................................^.^...^.^.^.^................................................................ +............................................................................................................................................. +...............................................................^.^.^...^...^.^............................................................... +............................................................................................................................................. +..............................................................^.^...^.^.^.^...^.............................................................. +............................................................................................................................................. +.............................................................^.....^...^.^.^.^.^............................................................. +............................................................................................................................................. +............................................................^.^.^.^.^...^.^.^...^............................................................ +............................................................................................................................................. +...........................................................^.....^.^.^.^...^...^.^........................................................... +............................................................................................................................................. +..........................................................^.^...^.......^.^.^.^.^.^.......................................................... +............................................................................................................................................. +.........................................................^.^.^.^.^.^.^.^.^.^...^.^.^......................................................... +............................................................................................................................................. +........................................................^.......^.^.^.^...^.^...^.^.^........................................................ +............................................................................................................................................. +.......................................................^.^.^.^...^.^...^...^...^...^.^....................................................... +............................................................................................................................................. +......................................................^.^...^.^.^.^...^.....^.^.^.^.^.^...................................................... +............................................................................................................................................. +.....................................................^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^..................................................... +............................................................................................................................................. +....................................................^.^.^...^.^.^.^...^.^...^.^...^...^.^.................................................... +............................................................................................................................................. +...................................................^.^.^.^.^.......^.^.^.^.^.^...^.^...^.^................................................... +............................................................................................................................................. +..................................................^.......^...^.^.^...^.....^.^.........^.^.................................................. +............................................................................................................................................. +.................................................^.^.^.^.^.^.^.^.^.^.^...^...^...^.^.....^.^................................................. +............................................................................................................................................. +................................................^...^.^...^.^.^.......^.....^...^...^.....^.^................................................ +............................................................................................................................................. +...............................................^.^.^...^.^...^...^.....^...^.^.^.^.^...^.^.^.^............................................... +............................................................................................................................................. +..............................................^.......^.^.^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^.............................................. +............................................................................................................................................. +.............................................^.^...^.^.^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^............................................. +............................................................................................................................................. +............................................^.^.^.^.....^...^.....^.^.^.^...^.^.^.^...^...^.^.^.^............................................ +............................................................................................................................................. +...........................................^.....^.^.^.......^.....^.^...^.^.^.^.^.^.^.^...^.^.^.^........................................... +............................................................................................................................................. +..........................................^.^.^.^.^.^...^.^.^.....^.^.....^...^.^.^.^.....^.^.^...^.......................................... +............................................................................................................................................. +.........................................^.^.^.^...............^.^.^...^.^.........^.^.^...^.^...^.^......................................... +............................................................................................................................................. +........................................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^...^.^.....^.^.^.^........................................ +............................................................................................................................................. +.......................................^...^.^.^.^.^.^.^.^...^...^.^.^.......^.^.^.^.^.^.........^...^....................................... +............................................................................................................................................. +......................................^.^.^.^.^.^...^.^.^.......^.....^...^.^.......^.^...^.^.^...^...^...................................... +............................................................................................................................................. +.....................................^.^.^.^.^.....^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^..................................... +............................................................................................................................................. +....................................^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^.^.^...^.^.^.^...^.^...^...^.................................... +............................................................................................................................................. +...................................^.^.^...^.^.^.^.^.^.......^.^.^.^.^...^.^.^.^.^.^.^.^...^.^...^.....^.^................................... +............................................................................................................................................. +..................................^.^...^.......^.^.^.^...^...^.^.....^.......^.^.^...^...^.^.^.^.^.^.^.^.^.................................. +............................................................................................................................................. +.................................^.^.....^...^.^.^...^...^.^.^.......^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^.^................................. +............................................................................................................................................. +................................^.....^.^.^...^.^...^...^...^.^.^.^...^.^.^.^...^.^...^.^.^.^...^.^.^...^...^................................ +............................................................................................................................................. +...............................^.^.^.^.^.......^...^.^...^...^.^.^.^.^.^...^.^.^.....^.^.^.^.^.......^.....^.^............................... +............................................................................................................................................. +..............................^...^...^.....^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^.^...^...^.^.^.........^.^.^.............................. +............................................................................................................................................. +.............................^.^.....^.....^...^.^.^.^...^.....^...^.^.^...^...^.^...^.^...^.^.^.^.^.^.^...^...^............................. +............................................................................................................................................. +............................^.^.^...^.^...^.^.^...^.^.^...^.^.^.^.....^...^.^.^.^.....^.^.^...^.^.^.^.^.^.^.^...^............................ +............................................................................................................................................. +...........................^.^.^.......^.^.^.^.^...^.^.^.^.^...^.....^.^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^...^.^........................... +............................................................................................................................................. +..........................^.^.....^...^.^.^...^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.^.^...^...^.^...^.^.^...^.^.^.......................... +............................................................................................................................................. +.........................^.^...^.^.^...^.^.^.^.^...^.^...^.............^.^.^.^.......^.^.^.^.^...^.^.^...^.^.^.^.^.^......................... +............................................................................................................................................. +........................^.^.........^.^.^.^.^.^...^.......^...^.^.^...^.^.^.....^.^.^.......^.....^.^.^.^.^.^.^.^.^.^........................ +............................................................................................................................................. +.......................^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.....^.^...^.^.^.^...^.^.^.^....................... +............................................................................................................................................. +......................^.^.^.^.......^.^.^...^.^...^.^...^...^.^...^...^.....^.^...^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^.^...................... +............................................................................................................................................. +.....................^.^.^.^...^...^...^.^.^.....^.^.^.^...^...^.^.^.^.^.........^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^..................... +............................................................................................................................................. +....................^.^.^...^...^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.....^...^.^.^.^.......^...^.^.^.^.^.^...^.^.^...^.^...^.................... +............................................................................................................................................. +...................^.^...^.^.^.^.^...^.^.^.^...^.^.^.^.^.^...^.^...^...^.^.^.^.......^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^................... +............................................................................................................................................. +..................^.^.^.^...^.....^.^...^...^.....^.....^.^...^...^...^.^.......^.........^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.................. +............................................................................................................................................. +.................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^.^.....^.^...^.....^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^................. +............................................................................................................................................. +................^.......^.^.^.^...^.^...^.^.^.^.^.^.^.......^.^.^.^.^.....^.^.^.^.^.^.....^.^.^...^...^.^.^...^.^.....^.^.^.^................ +............................................................................................................................................. +...............^.^.^.^.^.^.......^.^.^.......^.^.^...^.^.....^.^.........^.........^.^...^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^............... +............................................................................................................................................. +..............^.^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.^...^.^...^...^.^.^...^.^.^...^...^...^.^.^.^.^.^.^.........^.^.^.^.^.^.^.............. +............................................................................................................................................. +.............^.^.^.^.^.....^.^...^.^.^.....^.^.....^...^.^.....^.^.^...^.^.^.^...^...^.....^.^.^...^...^.^.....^.....^.....^...^............. +............................................................................................................................................. +............^.^.....^.^.^.^.^.^.^.^.^.....^...^.^.....^.^.^.^.^...^...^.^.^.^.^.^.^...^...^.....^.........^.....^.^.^.^.^.^...^.^............ +............................................................................................................................................. +...........^.^...^.^.^.^...^.......^...^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.......^.^...^........... +............................................................................................................................................. +..........^...^.^.^.^.........^.^.^.^.^...^.^.^.^...^.^.^.^.^.^.....^...^...^...^.^.^.^...^...^...^...^...^.......^...^...^.^...^.^.......... +............................................................................................................................................. +.........^...^.^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^...^.^...^.....^.^.....^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^......... +............................................................................................................................................. +........^.^...^.......^...^...^...^...^.........^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^...^.^...^.^...^.^.....^........ +............................................................................................................................................. +.......^...^.^.....^.^.^.^.^.^.^...^...^.^.^.^.....^.^.^...^.^.^...^.^...^...^.^.^.^.^.^.^.^...^.^.^.^.^.....^.^.^.^...^.^.^.^.^.^.^.^....... +............................................................................................................................................. +......^.^.^.........^.^.^...^...^.^...^.^.^.^...^.^...^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^.^...... +............................................................................................................................................. +.....^.^.....^.^...^.^.^...^...^.^.^.........^.^.^...^.^...^.^.^.^.^.^.^...^...^.^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.....^..... +............................................................................................................................................. +....^.^.^.....^...^.^.^.^.....^.....^...^.......^.^...^...^...^.^.^.^.^.....^.^.....^.^...^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^...^.... +............................................................................................................................................. +...^.^...^.^...^.^.^.^...^.^.......^.^.^.^.^...^...^.^...^...^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^.^...^... +............................................................................................................................................. +..^.^.^.^.^.....^...^.^.^.^...^.^...^...^.^.^.^...^...^...^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^...^...^...^.. +............................................................................................................................................. +.^.^...^.^.^...^.....^.^.^...^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^...^...^.^.^.....^.^...^...^.^.^.^.^.^.^.^. +............................................................................................................................................. diff --git a/2025/day07/part1.py b/2025/day07/part1.py new file mode 100644 index 0000000..d3aa221 --- /dev/null +++ b/2025/day07/part1.py @@ -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) diff --git a/2025/day07/part2.py b/2025/day07/part2.py new file mode 100644 index 0000000..8f497b5 --- /dev/null +++ b/2025/day07/part2.py @@ -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)) \ No newline at end of file