Skip to content

Commit

Permalink
Use modulo operator to limit the column
Browse files Browse the repository at this point in the history
Baseline: 0.0066704
  • Loading branch information
danielctull committed Dec 3, 2020
1 parent 104690e commit 6b48e83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Expand Up @@ -11,9 +11,9 @@
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.067099</real>
<real>0.0066704</real>
<key>baselineIntegrationDisplayName</key>
<string>3 Dec 2020 at 18:39:30</string>
<string>3 Dec 2020 at 18:46:29</string>
</dict>
</dict>
</dict>
Expand Down
6 changes: 2 additions & 4 deletions Year2020/Sources/Day03.swift
Expand Up @@ -21,11 +21,9 @@ public enum Day03 {

private static func count(input: Input, right: Int, down: Int) -> Int {
let columns = (0...).striding(by: right)
let rows = input.lines.striding(by: down).map { $0.cycled() }
let rows = input.lines.striding(by: down)
return zip(columns, rows).count(where: { column, row in
var iterator = row.dropFirst(column).makeIterator()
let character = iterator.next()!
return character == "#"
Array(row)[column % row.count] == "#"
})
}
}

0 comments on commit 6b48e83

Please sign in to comment.