File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -8,22 +8,25 @@ struct Day01: AdventDay {
88 data. split ( separator: " \n " ) . map { $0. split ( separator: " " ) }
99 }
1010
11+ var left : [ Int ] {
12+ lines. map { Int ( $0 [ 0 ] ) ?? 0 } . sorted ( )
13+ }
14+
15+ var right : [ Int ] {
16+ lines. map { Int ( $0 [ 1 ] ) ?? 0 } . sorted ( )
17+ }
18+
1119 // add here any computed values useful for the challenge
1220
1321 func part1( ) -> Int {
14- let listRight = lines. map { Int ( $0 [ 0 ] ) ?? 0 } . sorted ( )
15- let listLeft = lines. map { Int ( $0 [ 1 ] ) ?? 0 } . sorted ( )
1622 var sum = 0
17- for (one, two) in zip ( listLeft , listRight ) {
23+ for (one, two) in zip ( left , right ) {
1824 sum += abs ( one - two)
1925 }
2026 return sum
2127 }
2228
2329 func part2( ) -> Int {
24- let left = lines. map { Int ( $0 [ 0 ] ) ?? 0 } . sorted ( )
25- let right = lines. map { Int ( $0 [ 1 ] ) ?? 0 } . sorted ( )
26-
2730 var similarity = 0
2831 for elem in left {
2932 let occurrences = right. filter { $0 == elem } . count
You can’t perform that action at this time.
0 commit comments