04a
This commit is contained in:
parent
d341f9b45c
commit
42e442da09
@ -58,13 +58,16 @@ struct Day04 {
|
||||
.map { Int($0)! }
|
||||
_ = lines.removeFirst() //empty seperator line
|
||||
|
||||
let boards = lines
|
||||
let boardsInitial = lines
|
||||
.split(separator: "")
|
||||
.map { boardLines in
|
||||
Board(numbers: boardLines.map { $0.split(separator: " ").map { num in Int(num)! } })
|
||||
}
|
||||
var boardsA = boards
|
||||
runA(boards: &boardsA, inputNumbers: inputNumbers)
|
||||
var boards = boardsInitial
|
||||
runA(boards: &boards, inputNumbers: inputNumbers)
|
||||
|
||||
boards = boardsInitial
|
||||
runB(boards: &boards, inputNumbers: inputNumbers)
|
||||
}
|
||||
|
||||
func runA(boards: inout [Board], inputNumbers: [Int]) {
|
||||
@ -81,7 +84,17 @@ struct Day04 {
|
||||
}
|
||||
}
|
||||
|
||||
func runB(_ commands: [String]) {
|
||||
|
||||
func runB(boards: inout [Board], inputNumbers: [Int]) {
|
||||
for inputNumber in inputNumbers {
|
||||
//print("\nInput: \(inputNumber)")
|
||||
for (idx, var board) in boards.enumerated() {
|
||||
//print("Checking board: \(idx)")
|
||||
if !board.hasWon && board.crossOf(num: inputNumber) && board.checkHasWon() {
|
||||
print(board.calculateScore() * inputNumber)
|
||||
return
|
||||
}
|
||||
boards[idx] = board
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user