File tree 1 file changed +22
-3
lines changed
1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,26 @@ if (length(args) != 2) {
8
8
}
9
9
10
10
sns <- map(readLines(args [2 ]), ~ snailfish.parse(. ))
11
- res <- reduce(sns [- 1 ], ~ snailfish.add(.x , .y ), .init = sns [[1 ]])
12
11
13
- print(snailfish.toString(res ))
14
- print(snailfish.magnitude(res ))
12
+ if (args [[1 ]] == " part01" ) {
13
+ res <- reduce(sns [- 1 ], ~ snailfish.add(.x , .y ), .init = sns [[1 ]])
14
+ print(snailfish.toString(res ))
15
+ print(snailfish.magnitude(res ))
16
+ } else if (args [[1 ]] == " part02" ) {
17
+ max <- 0
18
+ for (i in seq_along(sns )) {
19
+ for (j in i : length(sns )) {
20
+ val <- snailfish.magnitude(snailfish.add(sns [[i ]], sns [[j ]]))
21
+ if (val > max ) {
22
+ max <- val
23
+ }
24
+ val <- snailfish.magnitude(snailfish.add(sns [[j ]], sns [[i ]]))
25
+ if (val > max ) {
26
+ max <- val
27
+ }
28
+ }
29
+ }
30
+ print(max )
31
+ } else {
32
+ print(" unknown subcommand" )
33
+ }
You can’t perform that action at this time.
0 commit comments