File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ Part 1: 13
2
+ Part 2: 30
You can’t perform that action at this time.
0 commit comments