Calculated syntax score directly
This commit is contained in:
parent
ec5a7feb3f
commit
ab1d21241b
@ -20,6 +20,7 @@ struct Day10: Runnable {
|
||||
.components(separatedBy: .newlines)
|
||||
var s = Deque<String.Element>()
|
||||
var illegalCharacters = [String.Element]()
|
||||
var syntaxScore = 0
|
||||
var autocompleteScores = [Int]()
|
||||
for line in lines {
|
||||
s = Deque<String.Element>()
|
||||
@ -36,7 +37,7 @@ struct Day10: Runnable {
|
||||
continue // Valid chunk
|
||||
}
|
||||
//print("Line: \(lineNumber): Expected \(shouldBeClosedBy), but found \(char) instead")
|
||||
illegalCharacters.append(char)
|
||||
syntaxScore += char.score!
|
||||
isIllegalLine = true
|
||||
break
|
||||
}
|
||||
@ -51,7 +52,7 @@ struct Day10: Runnable {
|
||||
autocompleteScores.append(lineScore)
|
||||
}
|
||||
}
|
||||
print(illegalCharacters.map{$0.score!}.reduce(0,+))
|
||||
print(syntaxScore)
|
||||
print(autocompleteScores.sorted()[autocompleteScores.count / 2])
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user