File tree Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ 190: 10 19
2
+ 3267: 81 40 27
3
+ 83: 17 5
4
+ 156: 15 6
5
+ 7290: 6 8 6 15
6
+ 161011: 16 10 13
7
+ 192: 17 8 14
8
+ 21037: 9 7 18 13
9
+ 292: 11 6 16 20
Original file line number Diff line number Diff line change
1
+ module main
2
+
3
+ import os
4
+
5
+ fn main () {
6
+ input := os.get_lines ()
7
+
8
+ ops := ['+' , '*' ]
9
+
10
+ mut sum := u64 (0 )
11
+ for line in input {
12
+ numbers := line.split (' ' ).map (it .u64 ())
13
+ mut acc := [numbers[1 ]]
14
+ for n2 in numbers[2 ..] {
15
+ mut nacc := []u64 {}
16
+ for n1 in acc {
17
+ for op in ops {
18
+ match op {
19
+ '+' { nacc << n1 + n2 }
20
+ '*' { nacc << n1 * n2 }
21
+ else {}
22
+ }
23
+ }
24
+ }
25
+ acc = nacc.clone ()
26
+ }
27
+ if acc.contains (numbers[0 ]) {
28
+ sum + = numbers[0 ]
29
+ }
30
+ }
31
+
32
+ println (sum)
33
+ }
Original file line number Diff line number Diff line change
1
+ module main
2
+
3
+ import os
4
+
5
+ fn main () {
6
+ input := os.get_lines ()
7
+
8
+ ops := ['+' , '*' , '||' ]
9
+
10
+ mut sum := u64 (0 )
11
+ for line in input {
12
+ numbers := line.split (' ' ).map (it .u64 ())
13
+ mut acc := [numbers[1 ]]
14
+ for n2 in numbers[2 ..] {
15
+ mut nacc := []u64 {}
16
+ for n1 in acc {
17
+ for op in ops {
18
+ match op {
19
+ '+' { nacc << n1 + n2 }
20
+ '*' { nacc << n1 * n2 }
21
+ '||' { nacc << '${n1}${n2} ' .u64 () }
22
+ else {}
23
+ }
24
+ }
25
+ }
26
+ acc = nacc.clone ()
27
+ }
28
+ if acc.contains (numbers[0 ]) {
29
+ sum + = numbers[0 ]
30
+ }
31
+ }
32
+
33
+ println (sum)
34
+ }
Original file line number Diff line number Diff line change
1
+ 3749
Original file line number Diff line number Diff line change
1
+ 11387
You can’t perform that action at this time.
0 commit comments