Skip to content

Commit c760c85

Browse files
committed
Completed day 4 of year 2025
1 parent 81481de commit c760c85

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

2025/4.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
def parser(data):
5+
row = []
6+
for line in data.split('\n'):
7+
row.append([c for c in line])
8+
9+
return row
10+
11+
split_data = parser
12+
completed = True
13+
raw_data = None # Not To be touched
14+
15+
mov = [(i, j) for i in range(-1, 2) for j in range(-1, 2) if (i, j) != (0, 0)]
16+
17+
def part1(data):
18+
counter = 0
19+
for y in range(len(data)):
20+
for x in range(len(data[y])):
21+
if data[y][x] != '@': continue
22+
c = 0
23+
for dx, dy in mov:
24+
nx, ny = x + dx, y + dy
25+
if 0 <= nx < len(data[y]) and 0 <= ny < len(data) and data[ny][nx] == '@':
26+
c += 1
27+
if c >= 4: break
28+
else:
29+
counter += 1
30+
31+
return counter
32+
33+
def part2(data):
34+
counter = 0
35+
36+
removed = True
37+
while removed:
38+
removed = False
39+
for y in range(len(data)):
40+
for x in range(len(data[y])):
41+
if data[y][x] != '@': continue
42+
c = 0
43+
for dx, dy in mov:
44+
nx, ny = x + dx, y + dy
45+
if 0 <= nx < len(data[y]) and 0 <= ny < len(data) and data[ny][nx] == '@':
46+
c += 1
47+
if c >= 4: break
48+
else:
49+
data[y][x] = '.'
50+
counter += 1
51+
removed = True
52+
53+
return counter

0 commit comments

Comments
 (0)