This commit is contained in:
Max Nuding 2021-12-06 19:37:25 +01:00
parent 900ddb6bb2
commit 1e865820a0
Signed by: phlaym
GPG Key ID: A06651BAB6777237
4 changed files with 67 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)]
)
]
)

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

@ -0,0 +1,49 @@
//
// File.swift
//
//
// Created by Max Nuding on 05.12.21.
//
import Foundation
import Runner
class Fish: CustomStringConvertible {
var timer: Int
var description: String { "\(timer)"}
init(timer: Int = 8) {
self.timer = timer
}
func tick() -> Fish? {
timer -= 1
if timer < 0 {
timer = 6
return Fish()
}
return nil
}
}
struct Day06: Runnable {
let inputPath: String
func run() {
let input = try! String(contentsOfFile: inputPath)
let internalCounters = input
.trimmingCharacters(in: .newlines)
.components(separatedBy: ",")
.map { Fish(timer: Int($0)!) }
run(fish: internalCounters, numDays: 80)
}
func run(fish: [Fish], numDays: Int) {
var tmpFish = fish
for _ in 1...numDays {
tmpFish.append(contentsOf: tmpFish.compactMap { $0.tick() })
}
print(tmpFish.count)
}
}

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