Compare commits
No commits in common. "85cfa9003d172772065be8c92dfd8d4b4a0edef4" and "900ddb6bb24b2c78f0171e18756b7de35acdb2e0" have entirely different histories.
85cfa9003d
...
900ddb6bb2
@ -14,8 +14,7 @@ let package = Package(
|
|||||||
.executable(name: "02", targets: ["02"]),
|
.executable(name: "02", targets: ["02"]),
|
||||||
.executable(name: "03", targets: ["03"]),
|
.executable(name: "03", targets: ["03"]),
|
||||||
.executable(name: "04", targets: ["04"]),
|
.executable(name: "04", targets: ["04"]),
|
||||||
.executable(name: "05", targets: ["05"]),
|
.executable(name: "05", targets: ["05"])
|
||||||
.executable(name: "06", targets: ["06"])
|
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// Dependencies declare other packages that this package depends on.
|
// Dependencies declare other packages that this package depends on.
|
||||||
@ -59,10 +58,6 @@ let package = Package(
|
|||||||
.targetItem(name: "Runner", condition: nil)
|
.targetItem(name: "Runner", condition: nil)
|
||||||
],
|
],
|
||||||
resources: []
|
resources: []
|
||||||
),
|
|
||||||
.executableTarget(
|
|
||||||
name: "06",
|
|
||||||
dependencies: [.targetItem(name: "Runner", condition: nil)]
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
//
|
|
||||||
// File.swift
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Created by Max Nuding on 05.12.21.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import Runner
|
|
||||||
|
|
||||||
struct Day06: Runnable {
|
|
||||||
let inputPath: String
|
|
||||||
|
|
||||||
func run() {
|
|
||||||
let input = try! String(contentsOfFile: inputPath)
|
|
||||||
let internalCounters = input
|
|
||||||
.trimmingCharacters(in: .newlines)
|
|
||||||
.components(separatedBy: ",")
|
|
||||||
.map { Int($0)! }
|
|
||||||
run(fish: internalCounters, numDays: 80)
|
|
||||||
run(fish: internalCounters, numDays: 256)
|
|
||||||
}
|
|
||||||
|
|
||||||
func run(fish: [Int], numDays: Int) {
|
|
||||||
var tmpFish = Dictionary(grouping: fish, by: { $0 }).mapValues { $0.count }
|
|
||||||
|
|
||||||
for _ in 1...numDays {
|
|
||||||
var d = [Int:Int]()
|
|
||||||
for f in tmpFish.keys.filter({$0 >= 0}) {
|
|
||||||
d[f-1] = tmpFish[f]
|
|
||||||
}
|
|
||||||
let countPregnant = d[-1] ?? 0
|
|
||||||
d[8] = countPregnant
|
|
||||||
d[6] = (d[6] ?? 0) + countPregnant
|
|
||||||
d[-1] = 0
|
|
||||||
|
|
||||||
tmpFish = d
|
|
||||||
}
|
|
||||||
print(tmpFish.values.reduce(0, +))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
//
|
|
||||||
// File.swift
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Created by Max Nuding on 05.12.21.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import Runner
|
|
||||||
|
|
||||||
Runner(target: Day06.self, day: "06").run()
|
|
@ -1 +0,0 @@
|
|||||||
1,2,1,3,2,1,1,5,1,4,1,2,1,4,3,3,5,1,1,3,5,3,4,5,5,4,3,1,1,4,3,1,5,2,5,2,4,1,1,1,1,1,1,1,4,1,4,4,4,1,4,4,1,4,2,1,1,1,1,3,5,4,3,3,5,4,1,3,1,1,2,1,1,1,4,1,2,5,2,3,1,1,1,2,1,5,1,1,1,4,4,4,1,5,1,2,3,2,2,2,1,1,4,3,1,4,4,2,1,1,5,1,1,1,3,1,2,1,1,1,1,4,5,5,2,3,4,2,1,1,1,2,1,1,5,5,3,5,4,3,1,3,1,1,5,1,1,4,2,1,3,1,1,4,3,1,5,1,1,3,4,2,2,1,1,2,1,1,2,1,3,2,3,1,4,5,1,1,4,3,3,1,1,2,2,1,5,2,1,3,4,5,4,5,5,4,3,1,5,1,1,1,4,4,3,2,5,2,1,4,3,5,1,3,5,1,3,3,1,1,1,2,5,3,1,1,3,1,1,1,2,1,5,1,5,1,3,1,1,5,4,3,3,2,2,1,1,3,4,1,1,1,1,4,1,3,1,5,1,1,3,1,1,1,1,2,2,4,4,4,1,2,5,5,2,2,4,1,1,4,2,1,1,5,1,5,3,5,4,5,3,1,1,1,2,3,1,2,1,1
|
|
@ -1 +0,0 @@
|
|||||||
3,4,3,1,2
|
|
Loading…
Reference in New Issue
Block a user