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