cosmetic fixes
This commit is contained in:
parent
40053ef992
commit
5780588903
@ -44,21 +44,20 @@ class Day14: Runnable {
|
|||||||
})
|
})
|
||||||
|
|
||||||
var pairCounts = [Pair:Int]()
|
var pairCounts = [Pair:Int]()
|
||||||
|
var charCount = [String.Element:Int](minimumCapacity: 26)
|
||||||
for i in startingPolymer.indices {
|
for i in startingPolymer.indices {
|
||||||
|
let firstCharacter = startingPolymer[i]
|
||||||
|
charCount[firstCharacter, default: 0] += 1
|
||||||
let next = startingPolymer.index(i, offsetBy: 1)
|
let next = startingPolymer.index(i, offsetBy: 1)
|
||||||
guard next != startingPolymer.endIndex else {
|
guard next != startingPolymer.endIndex else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pairCounts[Pair(first: startingPolymer[i], second: startingPolymer[next]), default: 0] += 1
|
pairCounts[Pair(first: firstCharacter, second: startingPolymer[next]), default: 0] += 1
|
||||||
}
|
}
|
||||||
var charCount = startingPolymer.reduce(into: [String.Element:Int](), {
|
|
||||||
$0[$1, default: 0] += 1
|
|
||||||
})
|
|
||||||
|
|
||||||
for step in 1...40 {
|
for step in 1...40 {
|
||||||
let tmpPairCounts = pairCounts
|
let tmpPairCounts = pairCounts
|
||||||
|
tmpPairCounts.forEach { pairCount in
|
||||||
for pairCount in tmpPairCounts {
|
|
||||||
let pair = pairCount.key
|
let pair = pairCount.key
|
||||||
let replacement = replacements[pair]!
|
let replacement = replacements[pair]!
|
||||||
pairCounts[pair]! -= pairCount.value
|
pairCounts[pair]! -= pairCount.value
|
||||||
|
Loading…
Reference in New Issue
Block a user