// // 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) } }