Skip to content

Commit

Permalink
AoC 2024: day 25 (Akuli#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Jan 5, 2025
1 parent 53d0e5d commit 3b7115c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ See the [examples](./examples/) and [tests](./tests/) directories for more examp
or read [the Jou tutorial](./doc/tutorial.md).

For now, Jou is great for writing small programs that don't have a lot of dependencies.
For example, I solved all problems of [Advent of Code 2023](https://adventofcode.com/2023/) in Jou,
and I'm currently working on Advent of Code 2024.
See [examples/aoc2023](./examples/aoc2023/)
and [examples/aoc2024](./examples/aoc2024/) for the code.
For example, I solved all problems of
[Advent of Code 2023](https://adventofcode.com/2023/) and
[Advent of Code 2024](https://adventofcode.com/2024/) with Jou. See
[examples/aoc2023](./examples/aoc2023/) and
[examples/aoc2024](./examples/aoc2024/) for the code.

I think Jou will be useful for two kinds of people:
- People who find C programming fun but like Python's syntax
Expand Down
56 changes: 56 additions & 0 deletions examples/aoc2024/day25/part1.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import "stdlib/io.jou"
import "stdlib/mem.jou"
import "../../aoc2023/grid.jou"


def fits(key: int*, lock: int*) -> bool:
for i = 0; i < 5; i++:
if key[i] + lock[i] > 5:
return False
return True


def main() -> int:
f = fopen("sampleinput.txt", "r")
assert f != NULL

keys: int[5][500]
locks: int[5][500]
nkeys = 0
nlocks = 0

while feof(f) == 0:
grid = read_grid_from_file(f)
assert grid.width == 5
assert grid.height == 7

dest: int*
if grid.get([0, 0]) == '#':
# lock
assert nlocks < sizeof(locks)/sizeof(locks[0])
dest = locks[nlocks++]
else:
# key
assert nkeys < sizeof(keys)/sizeof(keys[0])
dest = keys[nkeys++]

for x = 0; x < 5; x++:
count = -1 # ignore one full row
for y = 0; y < 7; y++:
if grid.get([x, y]) == '#':
count++
assert count >= 0
dest[x] = count

free(grid.data)

fclose(f)

result = 0
for il = 0; il < nlocks; il++:
for ik = 0; ik < nkeys; ik++:
if fits(keys[ik], locks[il]):
result++

printf("%d\n", result) # Output: 3
return 0
39 changes: 39 additions & 0 deletions examples/aoc2024/day25/sampleinput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#####
.####
.####
.####
.#.#.
.#...
.....

#####
##.##
.#.##
...##
...#.
...#.
.....

.....
#....
#....
#...#
#.#.#
#.###
#####

.....
.....
#.#..
###..
###.#
###.#
#####

.....
.....
.....
#....
#.#..
#.#.#
#####

0 comments on commit 3b7115c

Please sign in to comment.