From 534ae9c20afb9b178a80bf807fe7e6e02dfd0cdf Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sat, 11 Dec 2021 23:55:58 +0100 Subject: [PATCH] Day 11 --- day11.swift | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 day11.swift diff --git a/day11.swift b/day11.swift new file mode 100644 index 0000000..2d16909 --- /dev/null +++ b/day11.swift @@ -0,0 +1,70 @@ + +struct Day11 { + mutating func run() { + var count = 0 + var currentStep = 0 + repeat { + let stepCount = step() + count += stepCount + currentStep += 1 + if (currentStep == 100) { + print("Part 1:", count) + } + + if stepCount == width * height { + print("Part 2:", currentStep) + break + } + } while true + } + + subscript(x: Int, y: Int) -> Int { + get { data[x + width * y] } + set { data[x + width * y] = newValue } + } + + mutating func step() -> Int { + var flashes: Set = [] + + func up(x: Int, y: Int) { + self[x, y] += 1 + if self[x, y] > 9, flashes.insert(Point(x: x, y: y)).inserted { + for i in -1...1 where 0..