Skip to content

Commit b8d4068

Browse files
authored
Jackson Day 4, part 1, part 2 (#31)
1 parent 9822d6c commit b8d4068

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

2023/04/jacksonmowry.v

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module main
2+
3+
import os
4+
import arrays
5+
6+
fn main() {
7+
lines := os.read_lines('scratchcards.input')!
8+
mut part_1 := lines.map(it.split(': ')[1])
9+
.map(it.split('|').map(it.trim_space().split(' ').filter(it != '').map(it.int())))
10+
.map(arrays.concat(it[0], ...it[1]))
11+
.map(it.sorted())
12+
.map(arrays.uniq_only_repeated(it).len)
13+
println('Part 1: ${arrays.sum(part_1.filter(it != 0).map(1 << (it - 1)))!}')
14+
15+
mut counts := []int{len: lines.len, init: 1}
16+
for i := 0; i < part_1.len; i++ {
17+
for j := 1; j <= part_1[i]; j++ {
18+
counts[i + j] += counts[i]
19+
}
20+
}
21+
println('Part 2: ${arrays.sum[int](counts)!}')
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Part 1: 13
2+
Part 2: 30

0 commit comments

Comments
 (0)