Skip to content

Commit 695787f

Browse files
authored
2025 days 5-8 (#85)
1 parent 7230e69 commit 695787f

File tree

16 files changed

+339
-0
lines changed

16 files changed

+339
-0
lines changed

2025/05/.gitkeep

Whitespace-only changes.

2025/05/dy-tea.v

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
import arrays
3+
4+
lines := os.read_lines('ingredients.input')!
5+
mut sep_idx := 0
6+
for i, line in lines {
7+
if line == '' {
8+
sep_idx = i
9+
break
10+
}
11+
}
12+
ranges := lines[..sep_idx].map(fn (x string) []u64 {
13+
left, right := x.split_once('-') or { panic('invalid input') }
14+
return [left.u64(), right.u64()]
15+
})
16+
available := lines[sep_idx + 1..].map(|x| x.u64())
17+
18+
// part 1
19+
mut sum := u64(0)
20+
for id in available {
21+
for rn in ranges {
22+
left, right := rn[0], rn[1]
23+
if id >= left && id <= right {
24+
sum++
25+
break
26+
}
27+
}
28+
}
29+
println(sum)
30+
31+
// part 2
32+
mut merged := [][]u64{}
33+
for rn in ranges {
34+
mut nl := rn[0]
35+
mut nr := rn[1]
36+
mut removed := []int{}
37+
for i, ex in merged {
38+
el, er := ex[0], ex[1]
39+
if nl <= er + 1 && nr >= el - 1 {
40+
nl = if nl < el { nl } else { el }
41+
nr = if nr > er { nr } else { er }
42+
removed << i
43+
}
44+
}
45+
for i := removed.len - 1; i >= 0; i-- {
46+
merged.delete(removed[i])
47+
}
48+
merged << [nl, nr]
49+
}
50+
sum = arrays.sum(merged.map(|arr| arr[1] - arr[0] + 1))!
51+
println(sum)

2025/05/ingredients.input

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
3-5
2+
10-14
3+
16-20
4+
12-18
5+
6+
1
7+
5
8+
8
9+
11
10+
17
11+
32

2025/06/.gitkeep

Whitespace-only changes.

2025/06/dy-tea.v

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import regex as re
3+
import arrays
4+
5+
mut multiple_spaces := re.regex_opt(' +')!
6+
file := os.read_file('worksheet.input')!.split_any('\n\r')
7+
mut lines := [][]string{}
8+
for line in file {
9+
lines << multiple_spaces.split(line).filter(|s| s != '')
10+
}
11+
ops := lines.last()
12+
13+
// part 1
14+
mut sum := u64(0)
15+
for i in 0 .. ops.len {
16+
mut tmp := lines[0][i].u64()
17+
if ops[i] == '+' {
18+
for j in 1 .. lines.len - 1 {
19+
tmp += lines[j][i].u64()
20+
}
21+
} else {
22+
for j in 1 .. lines.len - 1 {
23+
tmp *= lines[j][i].u64()
24+
}
25+
}
26+
sum += tmp
27+
}
28+
println(sum)
29+
30+
// part 2
31+
sum = 0
32+
file_last := file.last()
33+
mut digits := []u64{}
34+
for j := file_last.len - 1; j >= 0; j-- {
35+
curr := file_last[j]
36+
mut st := ''
37+
for i in 0 .. file.len - 1 {
38+
st += file[i][j].ascii_str()
39+
}
40+
dig := st.replace(' ', '').u64()
41+
if dig != 0 {
42+
digits << dig
43+
}
44+
if curr != ` ` {
45+
if curr == `+` {
46+
sum += arrays.sum[u64](digits)!
47+
} else {
48+
sum += arrays.fold[u64, u64](digits, 1, |acc, elem| acc * elem)
49+
}
50+
digits.clear()
51+
}
52+
}
53+
println(sum)

2025/06/worksheet.input

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
123 328 51 64
2+
45 64 387 23
3+
6 98 215 314
4+
* + * +

2025/07/.gitkeep

Whitespace-only changes.

2025/07/dy-tea.v

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import arrays
3+
4+
lines := os.read_lines('manifolds.input')!
5+
s_index := lines[0].index('S') or { panic('S not found') }
6+
7+
// part 1
8+
mut x_indices := [s_index]
9+
mut count := u64(0)
10+
for y in 0 .. lines.len {
11+
mut x_after := []int{}
12+
for x in x_indices {
13+
if lines[y][x] == `^` {
14+
count++
15+
x_after << [x - 1, x + 1]
16+
} else {
17+
x_after << x
18+
}
19+
}
20+
mut seen := map[int]bool{}
21+
for pos in x_after {
22+
seen[pos] = true
23+
}
24+
x_indices = seen.keys()
25+
}
26+
println(count)
27+
28+
// part 2
29+
mut counts := map[int]u64{}
30+
counts[s_index] = 1
31+
for y in 0 .. lines.len {
32+
mut next := map[int]u64{}
33+
for x, val in counts {
34+
if lines[y][x] == `^` {
35+
next[x - 1] += val
36+
next[x + 1] += val
37+
} else {
38+
next[x] += val
39+
}
40+
}
41+
counts = next.move()
42+
}
43+
println(arrays.sum(counts.values()) or { panic('Failed to sum values') })

2025/07/manifolds.input

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.......S.......
2+
...............
3+
.......^.......
4+
...............
5+
......^.^......
6+
...............
7+
.....^.^.^.....
8+
...............
9+
....^.^...^....
10+
...............
11+
...^.^...^.^...
12+
...............
13+
..^...^.....^..
14+
...............
15+
.^.^.^.^.^...^.
16+
...............

2025/08/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)