Compare commits
2 Commits
900ddb6bb2
...
85cfa9003d
Author | SHA1 | Date | |
---|---|---|---|
85cfa9003d | |||
1e865820a0 |
@ -14,7 +14,8 @@ 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.
|
||||||
@ -58,6 +59,10 @@ let package = Package(
|
|||||||
.targetItem(name: "Runner", condition: nil)
|
.targetItem(name: "Runner", condition: nil)
|
||||||
],
|
],
|
||||||
resources: []
|
resources: []
|
||||||
|
),
|
||||||
|
.executableTarget(
|
||||||
|
name: "06",
|
||||||
|
dependencies: [.targetItem(name: "Runner", condition: nil)]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
41
Sources/06/06.swift
Normal file
41
Sources/06/06.swift
Normal 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
11
Sources/06/main.swift
Normal 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()
|
1
Sources/Runner/Resources/input/06.txt
Normal file
1
Sources/Runner/Resources/input/06.txt
Normal 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
|
1
Sources/Runner/Resources/input/06_test.txt
Normal file
1
Sources/Runner/Resources/input/06_test.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
3,4,3,1,2
|
Loading…
Reference in New Issue
Block a user