-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay07.swift
More file actions
46 lines (34 loc) · 1006 Bytes
/
Day07.swift
File metadata and controls
46 lines (34 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import AOCCore
import Foundation
struct Day07: Day {
let title = "Laboratories"
var rawInput: String?
func part1() throws -> Int {
let board = input().lines.map(\.characters)
guard
let startPosition = board.findFirst(element: "S")
else { return 0 }
var stack = [startPosition]
var visited: Set<Position> = []
var total = 0
while !stack.isEmpty {
guard
let current = stack.popLast(),
board[current] != nil,
!visited.contains(current)
else { continue }
if board[current] == "^" {
stack.append(current.offset(.downLeft))
stack.append(current.offset(.downRight))
total += 1
continue
}
visited.insert(current)
stack.append(current.offset(.down))
}
return total
}
func part2() throws -> Int {
-1
}
}