File tree Expand file tree Collapse file tree 1 file changed +46
-1
lines changed
Expand file tree Collapse file tree 1 file changed +46
-1
lines changed Original file line number Diff line number Diff line change 11# Advent of code Day 04
22# https://adventofcode.com/2025/day/4
33# 04/12/2025
4-
4+
5+ from tqdm .auto import tqdm
6+ from functools import reduce
7+
8+ with open ("input.txt" ) as file :
9+ inp = list (map (lambda row : list (row .strip ()), file .readlines ()))
10+
11+ def adjacents (i , j ):
12+ res = []
13+ for i1 in (i , i + 1 , i - 1 ):
14+ for j1 in (j , j + 1 , j - 1 ):
15+ if (i , j ) == (i1 , j1 ) or i1 < 0 or j1 < 0 : continue
16+ try :
17+ res .append (inp [i1 ][j1 ])
18+ except :
19+ pass
20+ return res
21+
22+ def hash (mat ):
23+ step1 = reduce (lambda a , b : a + b , mat , [])
24+ return reduce (lambda a , b : a + b , step1 , "" )
25+
26+ PAPER = "@"
27+ OTHER = "."
28+
29+ res1 = 0
30+ for i in range (len (inp )):
31+ for j in range (len (inp )):
32+ if inp [i ][j ] != PAPER : continue
33+ if adjacents (i , j ).count (PAPER ) < 4 :
34+ res1 += 1
35+
36+ res2 = 0
37+ newOnes = True
38+ while newOnes :
39+ newOnes = False
40+ for i in range (len (inp )):
41+ for j in range (len (inp )):
42+ if inp [i ][j ] != PAPER : continue
43+ if adjacents (i , j ).count (PAPER ) < 4 :
44+ res2 += 1
45+ inp [i ][j ] = OTHER
46+ newOnes = True
47+
48+
49+ print (res1 , res2 )
You can’t perform that action at this time.
0 commit comments