Compare commits

..

2 Commits

Author SHA1 Message Date
85cfa9003d
06b 2021-12-06 20:23:00 +01:00
1e865820a0
06a 2021-12-06 19:37:25 +01:00
5 changed files with 60 additions and 1 deletions

View File

@ -14,7 +14,8 @@ let package = Package(
.executable(name: "02", targets: ["02"]),
.executable(name: "03", targets: ["03"]),
.executable(name: "04", targets: ["04"]),
.executable(name: "05", targets: ["05"])
.executable(name: "05", targets: ["05"]),
.executable(name: "06", targets: ["06"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
@ -58,6 +59,10 @@ let package = Package(
.targetItem(name: "Runner", condition: nil)
],
resources: []
),
.executableTarget(
name: "06",
dependencies: [.targetItem(name: "Runner", condition: nil)]
)
]
)

41
Sources/06/06.swift Normal file
View File

@ -0,0 +1,41 @@
//
// 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, +))
}
}

11
Sources/06/main.swift Normal file
View File

@ -0,0 +1,11 @@
//
// File.swift
//
//
// Created by Max Nuding on 05.12.21.
//
import Foundation
import Runner
Runner(target: Day06.self, day: "06").run()

View File

@ -0,0 +1 @@
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

View File

@ -0,0 +1 @@
3,4,3,1,2