Calculated syntax score directly

This commit is contained in:
Max Nuding 2021-12-10 07:47:04 +01:00
parent ec5a7feb3f
commit ab1d21241b
Signed by: phlaym
GPG Key ID: A06651BAB6777237

View File

@ -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])
}
}