Skip to content

Commit 337d32d

Browse files
committed
2020/day1: Finish the part 2 solution
1 parent 950470f commit 337d32d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

2020/day1/solve.self

+20-4
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,35 @@
1414
0 to: integerValues size prec Do: [| :i. a |
1515
a: integerValues at: i.
1616
i succ to: integerValues size Do: [| :j. b |
17-
"'i: ' print. i _StringPrint. ' j: ' print. j _StringPrint. '' printLine."
18-
b: integerValues at: j.
17+
b: integerValues at: j.
1918
((a + b) = 2020) ifTrue: [
2019
^ a * b.
2120
].
2221
].
2322
].
2423
).
2524

26-
part2 = 'TODO part 2'.
25+
part2 = (| values. integerValues |
26+
values: input splitOn: ' '.
27+
integerValues: values copy.
28+
values do: [| :value. :i | integerValues at: i Put: value toInteger ].
29+
30+
0 to: integerValues size prec Do: [| :i. a |
31+
a: integerValues at: i.
32+
i succ to: integerValues size Do: [| :j. b |
33+
b: integerValues at: j.
34+
j succ to: integerValues size Do: [| :k. c |
35+
c: integerValues at: k.
36+
((a + b + c) = 2020) ifTrue: [
37+
^ a * b * c.
38+
].
39+
].
40+
].
41+
].
42+
).
2743

2844
main = (
2945
'Part 1: ' print. part1 _StringPrint. '' printLine.
30-
part2 printLine.
46+
'Part 2: ' print. part2 _StringPrint. '' printLine.
3147
).
3248
|) main.

0 commit comments

Comments
 (0)