File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,20 @@ namespace AdventOfCode.Y2022.Day03;
8
8
class Solution : Solver {
9
9
10
10
public object PartOne ( string input ) =>
11
+ // A line can be divided to two 'compartments' of equal length. We need
12
+ // to find the common item (letter) in them, and convert it to a number
13
+ // called 'priority'. Do this for each line and sum the priorities.
14
+ // We use 'chunk' to split a line in half.
11
15
input . Split ( "\n " )
12
16
. Select ( line => line . Chunk ( line . Length / 2 ) ) // 🥩
13
17
. Select ( GetCommonItemPriority )
14
18
. Sum ( ) ;
15
19
16
20
public object PartTwo ( string input ) =>
21
+ // Here we need to find the common item in three consecutive lines,
22
+ // convert it to priority as before, and sum it up along the whole
23
+ // input.
24
+ // This is again conveniently done using the chunk function.
17
25
input . Split ( "\n " )
18
26
. Chunk ( 3 )
19
27
. Select ( GetCommonItemPriority )
You can’t perform that action at this time.
0 commit comments