Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.7
rev: v0.14.8
hooks:
- id: ruff
args: [--fix]
- id: ruff-check
- id: ruff-format
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| 01 | [✓][012015] | | | | [✓][012019] | [✓][012020] | [✓][012021] | [✓][012022] | [✓][012023] | [✓][012024] | [✓][012025] |
| 02 | [✓][022015] | | | | [✓][022019] | [✓][022020] | [✓][022021] | [✓][022022] | [✓][022023] | [✓][022024] | [✓][022025] |
| 03 | [✓][032015] | | | | [✓][032019] | [✓][032020] | [✓][032021] | [✓][032022] | [✓][032023] | [✓][032024] | [✓][032025] |
| 04 | [✓][042015] | | | | [✓][042019] | [✓][042020] | [✓][042021] | [✓][042022] | [✓][042023] | [✓][042024] | |
| 04 | [✓][042015] | | | | [✓][042019] | [✓][042020] | [✓][042021] | [✓][042022] | [✓][042023] | [✓][042024] | [✓][042025] |
| 05 | [✓][052015] | | | | | [✓][052020] | | [✓][052022] | [✓][052023] | [✓][052024] | [✓][052025] |
| 06 | [✓][062015] | | | | | [✓][062020] | | [✓][062022] | [✓][062023] | [✓][062024] | |
| 07 | [✓][072015] | | | | | [✓][072020] | | [✓][072022] | [✓][072023] | [✓][072024] | |
Expand Down Expand Up @@ -132,7 +132,7 @@
[012025]: https://github.com/fabiogallotti/adventofcode/tree/master/src/year2025/day01
[022025]: https://github.com/fabiogallotti/adventofcode/tree/master/src/year2025/day02
[032025]: https://github.com/fabiogallotti/adventofcode/tree/master/src/year2025/day03

[042025]: https://github.com/fabiogallotti/adventofcode/tree/master/src/year2025/day04
[052025]: https://github.com/fabiogallotti/adventofcode/tree/master/src/year2025/day05

## To run an exercise ##
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description = ""
readme = "README.md"

[dependency-groups]
dev = ["pre-commit>=4.5.0", "pytest>=9.0.1", "ruff>=0.14.7"]
dev = ["pre-commit>=4.5.0", "pytest>=9.0.1", "ruff>=0.14.8"]

[build-system]
requires = ["pdm-backend"]
Expand Down
10 changes: 10 additions & 0 deletions src/year2025/day04/exercises.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from functions.read_input import read_input
from inputs.path import PATH

from .functions import part_1, part_2

data = read_input(f"{PATH}/2025/day04.txt")

print(f"First part: {part_1(data)}")

print(f"Second part: {part_2(data)}")
73 changes: 73 additions & 0 deletions src/year2025/day04/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from enum import Enum

from pydantic import BaseModel


class Position(BaseModel):
x: int
y: int

def __hash__(self):
return hash(str(self.x) + str(self.y))


class Direction(Enum):
UP = (-1, 0)
RIGHT = (0, 1)
DOWN = (1, 0)
LEFT = (0, -1)
UP_RIGHT = (-1, 1)
DOWN_RIGHT = (1, 1)
DOWN_LEFT = (1, -1)
UP_LEFT = (-1, -1)


def preprocessing(data):
paper = set()
for i in range(len(data)):
for j in range(len(data[0])):
elem = data[i][j]
if elem == "@":
paper.add(Position(x=i, y=j))

return paper


def part_1(data):
directions = list(Direction)
paper = preprocessing(data)
total = 0

for elem in paper:
count = 0
for direction in directions:
dx, dy = direction.value
next_pos = Position(x=elem.x + dx, y=elem.y + dy)
if next_pos in paper:
count += 1
if count < 4:
total += 1
return total


def part_2(data):
directions = list(Direction)
paper = preprocessing(data)
total = 0

while True:
to_remove = set()
for elem in paper:
count = 0
for direction in directions:
dx, dy = direction.value
next_pos = Position(x=elem.x + dx, y=elem.y + dy)
if next_pos in paper:
count += 1
if count < 4:
total += 1
to_remove.add(elem)
if not to_remove:
break
paper -= to_remove
return total
22 changes: 22 additions & 0 deletions tests/2025/test_2025day04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from year2025.day04.functions import part_1, part_2

EXAMPLE_1 = [
"..@@.@@@@.",
"@@@.@.@.@@",
"@@@@@.@.@@",
"@.@@@@..@.",
"@@.@@@@.@@",
".@@@@@@@.@",
".@.@.@.@@@",
"@.@@@.@@@@",
".@@@@@@@@.",
"@.@.@@@.@.",
]


def test_part_1():
assert part_1(EXAMPLE_1) == 13


def test_part_2():
assert part_2(EXAMPLE_1) == 43
42 changes: 21 additions & 21 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.