From 4d5c8ee8ce7f970edb8744693d9e0efb0a487226 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Wed, 23 Nov 2022 16:46:51 +0100 Subject: [PATCH] Add 2019 solutions --- 2019/AoC.playground/Contents.o | Bin 0 -> 3864 bytes 2019/AoC.playground/IntCode.o | Bin 0 -> 23144 bytes 2019/AoC.playground/IntCode.remap | 2 + .../Day 1.xcplaygroundpage/Contents.swift | 120 + .../Day 10.xcplaygroundpage/Contents.swift | 7 + .../Day 11.xcplaygroundpage/Contents.swift | 80 + .../Day 12.xcplaygroundpage/Contents.swift | 79 + .../Day 13.xcplaygroundpage/Contents.swift | 44 + .../Day 14.xcplaygroundpage/Contents.swift | 64 + .../Day 16.xcplaygroundpage/Contents.swift | 50 + .../Day 2.xcplaygroundpage/Contents.swift | 41 + .../Day 3.xcplaygroundpage/Contents.swift | 143 ++ .../Day 3.xcplaygroundpage/Sources/Heap.swift | 121 + .../timeline.xctimeline | 11 + .../Day 4.xcplaygroundpage/Contents.swift | 23 + .../Day 5.xcplaygroundpage/Contents.swift | 98 + .../Day 6.xcplaygroundpage/Contents.swift | 1974 +++++++++++++++++ .../Day 7.xcplaygroundpage/Contents.swift | 115 + .../Day 8.xcplaygroundpage/Contents.swift | 27 + .../Day 9.xcplaygroundpage/Contents.swift | 16 + 2019/AoC.playground/Sources/IntCode.swift | 118 + 2019/AoC.playground/Sources/Tools.swift | 28 + 2019/AoC.playground/Tools.o | Bin 0 -> 14848 bytes 2019/AoC.playground/Tools.remap | 2 + 2019/AoC.playground/contents.xcplayground | 20 + .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + 27 files changed, 3198 insertions(+) create mode 100644 2019/AoC.playground/Contents.o create mode 100644 2019/AoC.playground/IntCode.o create mode 100644 2019/AoC.playground/IntCode.remap create mode 100644 2019/AoC.playground/Pages/Day 1.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 10.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 11.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 12.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 13.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 14.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 16.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 2.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Sources/Heap.swift create mode 100644 2019/AoC.playground/Pages/Day 3.xcplaygroundpage/timeline.xctimeline create mode 100644 2019/AoC.playground/Pages/Day 4.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 5.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 6.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 7.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 8.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Pages/Day 9.xcplaygroundpage/Contents.swift create mode 100644 2019/AoC.playground/Sources/IntCode.swift create mode 100644 2019/AoC.playground/Sources/Tools.swift create mode 100644 2019/AoC.playground/Tools.o create mode 100644 2019/AoC.playground/Tools.remap create mode 100644 2019/AoC.playground/contents.xcplayground create mode 100644 2019/AoC.playground/playground.xcworkspace/contents.xcworkspacedata create mode 100644 2019/AoC.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/2019/AoC.playground/Contents.o b/2019/AoC.playground/Contents.o new file mode 100644 index 0000000000000000000000000000000000000000..b440b1a85f6a847e4491082781cb7ae1022ee088 GIT binary patch literal 3864 zcmb_fO>7%Q6du?4gBGhol?W7wK{@2mpg1ig5{hKUNl1jjAscAa%hX=4lTFvV)_R>E z${`XLgiw`8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w~Yle=EqbJ zT~&`cNV|A2hEYBjI>f}j9Y@%vcTkB?sO~hIm07W}b9AG(Hfwcl=w_GT-B(r(#z8Cf z&_YX7|1hPsjf$Ub;daV^miuYpR_DfrTb7w3)PTZFh}8m_)mGm9W#$)Egl$VEETx&bsv1L>VHQaQ)f?Np&m*IK!j)+g6wKuf{ zJgw2_O?Uc`Pj%+JMZ#8AyE>u^?#5POUir$uiq6XN5me^fnUpTTlk&JGt19j4>Wr2y zP$OY+S($DatavaW9d>zGxUAGmSIWUyw63M=0lcU%=#Et^4fxtobXOPX710M>4J&Y> zD(bsDllk+st+%<0G7^T3w~TmBSIXuoSDb!qy*z=gE|*K1t#4gk3D*uQ&NP{W)v`op zip=O*bzV+$PE~gMbIzi&p38G{#25BqJ`1+;PLJlxPMWD$b?%*I*-ZiEZj}eGj>K#2 z$`<4+$K63ce%FBpEBw()S5-}o%e6S{Uc6zkzl_yn-3|<`bGqq3&Z&ke zHPcZ!E@tQ@et}qf_-5?y+<2E}5chVP-A1YmBt#Y(M2u7!NQhJzM2u7!NQf*jh#09d zkPx}aAY!D-Ktg1`K?D@a%8Z3XqI8}?5)?@q3yDN&xk1uIfuxGYQX;9;P|--0gCr4S vDUm2GHB>AINutJ5kQcFKt-X Int { + let requiredFuel = mass / 3 - 2 + guard requiredFuel > 0 else { + return 0 + } + + return requiredFuel + fuel(mass: requiredFuel) +} + +input.split(separator: "\n") + .compactMap { Int($0) } + .map { fuel(mass: $0) } + .reduce(0, { a, b -> Int in a + b }) + + diff --git a/2019/AoC.playground/Pages/Day 10.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 10.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..854a033 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 10.xcplaygroundpage/Contents.swift @@ -0,0 +1,7 @@ +//: [Previous](@previous) + +import Foundation + +var str = "Hello, playground" + +//: [Next](@next) diff --git a/2019/AoC.playground/Pages/Day 11.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 11.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..10491c6 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 11.xcplaygroundpage/Contents.swift @@ -0,0 +1,80 @@ +let program = [3,8,1005,8,339,1106,0,11,0,0,0,104,1,104,0,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,29,2,1108,11,10,1,1,20,10,2,107,6,10,3,8,102,-1,8,10,101,1,10,10,4,10,108,0,8,10,4,10,101,0,8,62,1006,0,29,1006,0,12,1,1101,5,10,1,2,20,10,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,0,10,4,10,1001,8,0,99,1006,0,30,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,0,10,4,10,1001,8,0,124,1006,0,60,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,149,2,1007,2,10,1,1105,10,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,101,0,8,178,1,1108,15,10,1,1101,5,10,1,109,8,10,1006,0,20,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,101,0,8,215,1006,0,61,1006,0,16,2,1105,15,10,1006,0,50,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,1,8,10,4,10,101,0,8,250,1,1003,10,10,1,9,19,10,2,1004,6,10,2,1106,2,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,289,1,1103,13,10,2,105,17,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,1,8,10,4,10,1002,8,1,318,101,1,9,9,1007,9,1086,10,1005,10,15,99,109,661,104,0,104,1,21101,0,825599304340,1,21101,356,0,0,1106,0,460,21101,0,937108545948,1,21102,1,367,0,1106,0,460,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21102,1,21628980315,1,21101,0,414,0,1105,1,460,21101,0,3316673539,1,21101,425,0,0,1106,0,460,3,10,104,0,104,0,3,10,104,0,104,0,21102,988753428840,1,1,21102,1,448,0,1106,0,460,21102,825544569700,1,1,21102,459,1,0,1106,0,460,99,109,2,21202,-1,1,1,21102,1,40,2,21102,491,1,3,21102,481,1,0,1105,1,524,109,-2,2106,0,0,0,1,0,0,1,109,2,3,10,204,-1,1001,486,487,502,4,0,1001,486,1,486,108,4,486,10,1006,10,518,1101,0,0,486,109,-2,2105,1,0,0,109,4,2102,1,-1,523,1207,-3,0,10,1006,10,541,21102,0,1,-3,21201,-3,0,1,22102,1,-2,2,21102,1,1,3,21102,560,1,0,1106,0,565,109,-4,2105,1,0,109,5,1207,-3,1,10,1006,10,588,2207,-4,-2,10,1006,10,588,22101,0,-4,-4,1105,1,656,21202,-4,1,1,21201,-3,-1,2,21202,-2,2,3,21102,1,607,0,1106,0,565,22102,1,1,-4,21101,0,1,-1,2207,-4,-2,10,1006,10,626,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,648,21202,-1,1,1,21101,0,648,0,105,1,523,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2105,1,0] + +class Robot: IO { + static let size = 1000 + static let colorMask = 1 << 0 + static let paintedMask = 1 << 1 + + var position = (x:Robot.size / 2, y: Robot.size / 2) + var direction = 0 + + var colors = Array(repeating: 0, count: Robot.size * Robot.size) + var paintedCells = 0 + var nextIsPaint = true + + var minX = Robot.size + var maxX = 0 + var minY = Robot.size + var maxY = 0 + + func move(turn: Int) { + direction = (4 + direction + (turn == 0 ? -1 : 1)) % 4 + switch direction { + case 0: position.y -= 1 + case 1: position.x += 1 + case 2: position.y += 1 + case 3: position.x -= 1 + default: fatalError() + } + } + + func input() -> Int { + return colors[position] & Robot.colorMask + } + + func output(_ value: Int) { + precondition(value == 0 || value == 1) + if nextIsPaint { + if colors[position] & Robot.paintedMask == 0 { + paintedCells += 1 + } + colors[position] = value | Robot.paintedMask + + minX = min(position.x, minX) + maxX = max(position.x, maxX) + minY = min(position.y, minY) + maxY = max(position.y, maxY) + } else { + move(turn: value) + } + nextIsPaint.toggle() + } +} + +extension Array { + subscript(pos: (Int, Int)) -> Element { + get { + let (x, y) = pos + precondition(0.. Int +{ + if a < b { + return 1 + } else if a == b { + return 0 + } else { + return -1 + } +} + + +var moons = [ + Moon(x: -13, y: 14, z: -7), + Moon(x: -18, y: 9, z: 0), + Moon(x: 0, y: -3, z: -3), + Moon(x: -15, y: 3, z: -13) +] + +@discardableResult +func step() -> Int { + for a in 0.. = [] + +var steps = 0 + +repeat { + seen.insert(moons) + step() + steps += 1 +} while !seen.contains(moons) + diff --git a/2019/AoC.playground/Pages/Day 13.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 13.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..a03eb5c --- /dev/null +++ b/2019/AoC.playground/Pages/Day 13.xcplaygroundpage/Contents.swift @@ -0,0 +1,44 @@ +let program = [2,380,379,385,1008,2663,704183,381,1005,381,12,99,109,2664,1102,1,0,383,1102,0,1,382,20102,1,382,1,21001,383,0,2,21102,37,1,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,44,381,1005,381,22,1001,383,1,383,1007,383,23,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1105,1,161,107,1,392,381,1006,381,161,1102,-1,1,384,1105,1,119,1007,392,42,381,1006,381,161,1101,0,1,384,20102,1,392,1,21102,21,1,2,21102,1,0,3,21102,138,1,0,1105,1,549,1,392,384,392,20101,0,392,1,21102,21,1,2,21101,3,0,3,21101,0,161,0,1106,0,549,1101,0,0,384,20001,388,390,1,21002,389,1,2,21102,180,1,0,1106,0,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,20102,1,389,2,21101,0,205,0,1105,1,393,1002,390,-1,390,1102,1,1,384,21001,388,0,1,20001,389,391,2,21102,1,228,0,1106,0,578,1206,1,261,1208,1,2,381,1006,381,253,20102,1,388,1,20001,389,391,2,21101,253,0,0,1105,1,393,1002,391,-1,391,1101,1,0,384,1005,384,161,20001,388,390,1,20001,389,391,2,21101,0,279,0,1105,1,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1106,0,393,1002,390,-1,390,1002,391,-1,391,1101,0,1,384,1005,384,161,20102,1,388,1,21002,389,1,2,21102,0,1,3,21101,0,338,0,1106,0,549,1,388,390,388,1,389,391,389,21002,388,1,1,21001,389,0,2,21102,1,4,3,21102,365,1,0,1105,1,549,1007,389,22,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,414,20,18,1,1,22,109,3,22102,1,-2,1,21202,-1,1,2,21102,1,0,3,21101,0,414,0,1106,0,549,21201,-2,0,1,21202,-1,1,2,21101,429,0,0,1105,1,601,1201,1,0,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2106,0,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,22102,1,-3,-7,109,-8,2106,0,0,109,4,1202,-2,44,566,201,-3,566,566,101,639,566,566,2101,0,-1,0,204,-3,204,-2,204,-1,109,-4,2105,1,0,109,3,1202,-1,44,594,201,-2,594,594,101,639,594,594,20101,0,0,-2,109,-3,2106,0,0,109,3,22102,23,-2,1,22201,1,-1,1,21102,509,1,2,21102,150,1,3,21101,1012,0,4,21102,630,1,0,1106,0,456,21201,1,1651,-2,109,-3,2105,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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16,77,73,84,85,36,89,77,79,82,37,7,24,68,14,78,75,7,86,80,18,84,68,62,89,7,64,11,9,56,62,3,29,95,41,23,18,90,1,10,4,94,8,69,57,13,72,89,61,72,61,17,54,88,96,53,73,21,92,16,52,18,26,89,32,2,50,8,3,5,36,26,64,75,51,55,49,45,78,49,27,55,2,29,37,77,69,3,21,69,6,18,59,91,57,92,6,26,58,40,26,54,33,40,96,45,89,23,53,94,61,44,32,33,41,12,31,67,17,96,34,72,72,49,90,21,1,40,75,97,56,57,77,20,21,68,14,4,7,9,41,88,32,40,79,77,17,48,70,56,50,67,36,16,98,98,65,98,53,7,36,47,27,15,77,80,83,39,8,22,61,11,9,10,54,16,65,54,82,60,66,21,92,51,70,17,53,22,39,89,92,29,12,60,37,42,75,65,1,61,90,86,46,62,81,2,64,64,21,43,17,46,57,72,25,63,51,30,22,65,81,54,85,45,93,24,23,23,27,37,94,11,15,93,78,75,11,41,56,42,89,20,73,23,27,98,89,29,68,73,89,75,80,31,90,36,62,44,65,18,97,24,22,84,30,56,41,44,67,63,71,85,76,66,64,51,58,98,30,66,4,90,38,8,49,49,62,55,53,5,74,18,93,4,34,48,86,17,37,35,28,45,38,76,95,67,21,67,6,36,38,1,16,5,8,89,9,37,32,78,90,46,92,61,3,96,40,91,31,98,35,90,96,44,43,55,39,51,64,51,39,12,90,58,69,58,39,13,49,60,35,40,56,56,74,47,54,23,8,54,59,97,12,8,62,21,66,59,96,61,54,12,98,28,85,95,2,4,14,89,78,4,16,66,48,37,43,17,59,77,20,63,28,87,10,20,58,46,55,26,94,3,71,5,13,90,67,68,55,93,38,16,28,45,47,41,88,98,90,95,44,33,89,54,24,33,38,94,79,32,15,62,26,52,39,8,22,38,79,3,60,75,55,91,53,36,59,86,1,98,25,87,84,47,83,40,74,22,91,86,73,73,6,15,72,90,43,87,97,63,24,77,20,76,10,96,65,27,69,87,93,17,34,5,52,31,24,46,4,26,3,34,87,96,68,16,82,85,67,65,11,57,71,49,62,77,5,68,20,51,26,40,67,69,32,82,46,57,15,31,81,38,74,98,3,77,78,36,10,55,76,48,90,2,8,21,29,17,66,51,91,59,36,8,2,85,50,53,76,38,91,24,54,6,6,28,20,25,7,56,87,44,54,98,6,10,94,44,93,25,26,65,22,87,52,47,36,1,22,21,32,49,7,72,66,89,92,63,85,90,82,79,33,36,39,69,15,57,80,46,39,28,79,73,43,95,81,21,47,39,68,30,34,79,33,72,14,54,96,52,60,16,9,73,54,78,77,26,89,14,14,28,83,47,81,87,14,86,11,96,29,10,2,84,1,70,59,81,64,29,25,40,53,87,4,42,76,80,48,39,85,60,96,95,78,30,8,83,46,62,68,82,40,15,43,51,81,65,64,3,81,13,48,70,97,95,6,23,91,66,63,22,70,28,10,42,90,91,80,34,29,48,18,96,78,14,17,88,13,96,72,72,86,45,95,59,20,67,65,35,89,46,76,35,7,35,4,64,58,15,98,39,81,2,95,10,75,56,85,22,31,22,14,9,12,48,15,75,91,85,91,26,40,78,23,76,5,45,6,79,58,4,70,7,10,79,56,98,86,34,18,73,57,70,97,72,59,75,36,30,21,41,38,83,93,64,92,89,17,65,19,93,9,83,51,3,20,71,89,37,70,3,90,13,35,95,43,14,78,3,43,15,11,21,36,50,12,27,47,58,18,8,66,23,32,7,88,82,27,21,23,5,80,79,44,87,19,11,47,15,14,18,14,95,54,81,76,93,51,53,63,97,39,11,30,26,89,6,29,15,21,49,57,53,52,93,83,11,95,28,58,79,22,65,58,93,89,60,49,78,55,22,42,25,14,61,66,28,84,43,4,68,54,68,17,46,13,88,30,39,40,35,35,14,69,34,55,93,43,7,20,82,83,50,25,50,26,78,17,93,7,10,24,3,27,85,97,88,62,65,11,66,36,38,14,32,31,94,14,3,38,39,96,23,64,89,91,37,9,5,44,4,18,43,64,53,58,96,84,67,96,24,86,49,30,49,24,4,46,57,704183] + +class Arcade: IO { + func input() -> Int { + return 0 + } + + var buffer: [Int] = [] + + static let size = 1000 + var screen = Array2d(initial: 0, width: 44, height: 23) + var score = 0 + + var maxX = 0 + var maxY = 0 + + func output(_ value: Int) { + buffer.append(value) + if buffer.count == 3 { + if buffer[0...1] == [-1, 0] { + score = buffer[2] + print("score>", score) + } else { + maxX = max(maxX, buffer[0]) + maxY = max(maxY, buffer[1]) + + screen[(buffer[0], buffer[1])] = buffer[2] + } + buffer.removeAll(keepingCapacity: true) + } + } +} + + +let arcade = Arcade() + +IntCode(program: program, io: arcade).run() + +let blocks = arcade.screen.data.reduce(0, { $0 + ($1 == 2 ? 1 : 0) } ) +blocks + +arcade.maxX +arcade.maxY + diff --git a/2019/AoC.playground/Pages/Day 14.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 14.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..b82c775 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 14.xcplaygroundpage/Contents.swift @@ -0,0 +1,64 @@ +import Foundation + +let input = """ +9 ORE => 2 A +8 ORE => 3 B +7 ORE => 5 C +3 A, 4 B => 1 AB +5 B, 7 C => 1 BC +4 C, 1 A => 1 CA +2 AB, 3 BC, 4 CA => 1 FUEL +""" + + +struct Chemical { + let name: String + let amount: Int +} + +struct Reaction { + let product: Chemical + let educts: [Chemical] +} + +var reactions: [String: Reaction] = [:] + +let scanner = Scanner(string: input) + +func parseChemical() -> Chemical? { + guard let amount = scanner.scanInt(), + let name = scanner.scanCharacters(from: .letters) else { + return nil + } + return Chemical(name: name, amount: amount) +} + +func parseReaction() -> Reaction? { + var educts: [Chemical] = [] + repeat { + guard let chemical = parseChemical() else { + return nil + } + educts.append(chemical) + } while scanner.scanString(",") != nil + guard scanner.scanString("=>") != nil else { + return nil + } + guard let product = parseChemical() else { + return nil + } + + return Reaction(product: product, educts: educts) +} + +while !scanner.isAtEnd { + guard let reaction = parseReaction() else { + fatalError() + } + + reactions[reaction.product.name] = reaction +} + + + + diff --git a/2019/AoC.playground/Pages/Day 16.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 16.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..07bd13c --- /dev/null +++ b/2019/AoC.playground/Pages/Day 16.xcplaygroundpage/Contents.swift @@ -0,0 +1,50 @@ + +func pattern(position: Int) -> DropFirstSequence> +{ + precondition(position >= 0) + let repeats = position + 1 + + let base = [0, 1, 0, -1] + return repeating(base.flatMap { Array(repeating: $0, count: repeats) }).dropFirst() +} + +func repeating(_ sequence: T) -> AnySequence +{ + return AnySequence { () -> AnyIterator in + var it = sequence.makeIterator() + return AnyIterator { () -> T.Element? in + if let value = it.next() { + return value + } + + it = sequence.makeIterator() + return it.next() + } + } +} + +func phase(_ input: [Int]) -> [Int] { + var result: [Int] = [] + return input.indices.map { i in + abs(zip(input, pattern(position: i)).reduce(0) { (accum: Int, value: (Int, Int)) -> Int in accum + value.0 * value.1 }) % 10 + } + } + +let input = "59773419794631560412886746550049210714854107066028081032096591759575145680294995770741204955183395640103527371801225795364363411455113236683168088750631442993123053909358252440339859092431844641600092736006758954422097244486920945182483159023820538645717611051770509314159895220529097322723261391627686997403783043710213655074108451646685558064317469095295303320622883691266307865809481566214524686422834824930414730886697237161697731339757655485312568793531202988525963494119232351266908405705634244498096660057021101738706453735025060225814133166491989584616948876879383198021336484629381888934600383957019607807995278899293254143523702000576897358" + +var data: [Int] = input.map { $0.wholeNumberValue! } + +func readAt(_ index: Int) -> Int { + data[index ..< index + 8].reduce(0) { 10 * $0 + $1 } +} + +readAt(readAt(0)) + + +//for i in 0..<100 { +// data = phase(data) +//} +// +//print(data[0..<8]) + + diff --git a/2019/AoC.playground/Pages/Day 2.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 2.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..36d110e --- /dev/null +++ b/2019/AoC.playground/Pages/Day 2.xcplaygroundpage/Contents.swift @@ -0,0 +1,41 @@ +let program = [1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,10,1,19,1,5,19,23,1,23,5,27,1,27,13,31,1,31,5,35,1,9,35,39,2,13,39,43,1,43,10,47,1,47,13,51,2,10,51,55,1,55,5,59,1,59,5,63,1,63,13,67,1,13,67,71,1,71,10,75,1,6,75,79,1,6,79,83,2,10,83,87,1,87,5,91,1,5,91,95,2,95,10,99,1,9,99,103,1,103,13,107,2,10,107,111,2,13,111,115,1,6,115,119,1,119,10,123,2,9,123,127,2,127,9,131,1,131,10,135,1,135,2,139,1,10,139,0,99,2,0,14,0] + + + +func run(a: Int, b: Int) -> Int { + var memory = program + + memory[1] = a + memory[2] = b + + var pc = 0 + + loop: while(true) { + switch memory[pc] { + case 1: + memory[memory[pc + 3]] = memory[memory[pc + 1]] + memory[memory[pc + 2]] + + case 2: + memory[memory[pc + 3]] = memory[memory[pc + 1]] * memory[memory[pc + 2]] + + case 99: + break loop + + default: + fatalError() + + } + pc += 4 + } + + return memory[0] +} + +for a in 0...99 { + for b in 0...99 { + if run(a: a, b: b) == 19690720 { + print (100 * a + b) + } + } +} + diff --git a/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..67e6ff9 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Contents.swift @@ -0,0 +1,143 @@ +import Foundation + +//let in1 = "R1002,D715,R356,D749,L255,U433,L558,D840,R933,U14,L285,U220,L88,D477,R36,U798,R373,U378,R305,D341,R959,D604,R717,D911,L224,D32,R481,D508,L203,U445,L856,U44,L518,U909,R580,U565,R484,D170,R356,U614,R278,U120,R540,D330,R124,D555,R890,U445,L876,D948,R956,D503,R391,U564,R624,D642,L821,U924,L921,U869,R104,U376,L693,U812,R758,U200,L515,U435,R505,U22,R707,U926,R261,D332,R535,D704,L561,U476,R225,U168,L784,D794,R311,D426,R813,U584,L831,D258,R241,D665,R550,D709,R261,U557,L670,D823,L297,U951,R634,D647,R699,U907,L219,U481,L583,D854,L898,U535,R648,U307,L870,D748,R768,D502,L15,U684,R476,D591,L531,D881,L466,U135,R445,U813,R950,D303,L590,U938,R630,D233,R567,U739,L446,U689,R585,D892,R741,U849,R629,D972,L625,D524,L715,D936,L328,U102,R864,U859,L827,U162,L886,D785,R359,D38,R51,U999,R560,U415,L840,U736,R552,D277,R722,D444,R164,U335,L129,D873,L499,U847,R84,U780,R104,U879,R938,D468,L575,D668,L143,U917,R86,D562,R595,U924,R807,U76,L44,D685,R936,U876,R570,U782,L139,D815,R89,D976,R84,U446,R238,U853,L603,U869,R312,U970,R387,U131,L647,D383,R161,D818,L765,U291,L423,D753,R277,U840,R23,U265,R298,U665,R522,D955,R26,D320,R347,U952,R743,U782,L780,D20,L393,U855,L279,D969,L923,D902,L818,U855,L927,D342,R769,U517,L485,U176,R14,U683,L632,U198,R656,U444,R41,D911,R99,U880,L363,D15,L894,D782,R612,D677,R469,D166,R61,U284,R474,U222,L687,D502,R690,U619,R536,D663,L54,D660,L804,D697,R67,U116,R842,D785,R277,U978,L920,D926,R681,D957,L582,U441,L593,U686,R829,U937,L924,U965,R727,D964,R468,U240,R934,D266,R416" +//let in2 = "L998,U258,R975,U197,R680,D56,R898,D710,R475,U909,L201,D579,L21,U743,R832,D448,R216,D136,R83,U413,R167,U138,R102,U122,L290,D49,L93,D941,L625,U709,R129,D340,L322,D27,R440,U692,R368,D687,L246,D425,R823,U287,L436,U999,R90,U663,R470,U177,R956,D981,L767,D780,R610,D644,R238,D416,R402,D327,L680,D367,L94,D776,L331,D745,R846,D559,R113,U158,R125,D627,L898,D212,L80,D184,L386,U943,R122,D614,L868,D600,R912,U501,R25,D887,R310,U872,L157,U865,L382,U959,R712,D248,L343,U819,L763,U886,R582,D631,L835,U443,L917,D934,L333,U470,R778,U142,R384,U589,R306,U933,L206,D199,L497,D406,L212,U439,L15,U985,R505,D502,R934,D966,R429,U810,R588,U367,L424,U804,R767,U703,R885,U568,R748,U209,L319,U305,L941,D184,R398,U681,L411,U414,L90,U711,L575,D368,L986,U29,R982,U361,L501,D970,R558,D887,L241,U506,R578,D932,R911,U621,L153,U200,L873,U711,L843,U549,R72,U377,R915,D79,L378,U66,L989,D589,L341,D350,L200,D78,R944,U876,L794,U643,R871,D909,L353,D54,R651,U338,R857,D938,R636,D301,R728,U318,R530,D589,L682,U784,L428,D879,L207,D247,L53,U312,L488,D534,L998,U512,L628,D957,L994,D747,L804,U399,L801,D500,R791,D980,R839,U564,L81,U461,R615,U863,R308,D564,R843,U579,R792,D472,R229,D153,L21,D647,R425,D54,L470,U330,R285,D81,L221,U168,R970,D624,R815,U189,L812,U195,L654,U108,R820,U786,L932,U657,L605,D164,L788,D393,L717,D49,R615,D81,L91,U322,L150,D368,R434,D861,L859,D911,R161,U576,L671,U992,L745,U585,R440,D731,R740,U584,L867,D906,R176,U72,L323,U329,L445,D667,R626,D111,L895,D170,R957,D488,R214,D354,L215,U486,L665,D266,L987" + +let in1 = "R8,U5,L5,D3" +let in2 = "U7,R6,D4,L4" +struct LineSegment: Equatable { + let first: Bool + let startLength: Int + let x0: Int + let y0: Int + let symbol: String +} + +enum Entry: Equatable { + case start(x: Int, y: Int, LineSegment) + case end(x: Int, y: Int, LineSegment) + case vertical(x: Int, y0: Int, y1: Int, LineSegment) + + var x: Int { + switch self { + case .start(let x, _, _): return x + case .end(let x, _, _): return x + case .vertical(let x, _, _, _): return x + } + } +} + +extension Entry: Comparable { + static func < (lhs: Entry, rhs: Entry) -> Bool { + return lhs.x < rhs.x + } +} + +var segments = Heap() + + + +func parse(_ s: String, first: Bool) { + var x = 0 + var y = 0 + let s = Scanner(string: s) + var len = 0 + + loop: repeat { + guard let dir = s.scanCharacter(), + let amount = s.scanInt() else { + break + } + + let symbol = "\(dir)\(amount)" + + switch dir { + case "R": + let seg = LineSegment(first: first, startLength: len, x0: x, y0: y, symbol: symbol) + segments.insert(item: .start(x: x, y: y, seg)) + x += amount + segments.insert(item: .end(x: x, y: y, seg)) + + case "L": + let seg = LineSegment(first: first, startLength: len, x0: x - amount, y0: y, symbol: symbol) + segments.insert(item: .end(x: x, y: y, seg)) + x -= amount + segments.insert(item: .start(x: x, y: y, seg)) + + case "U": + let seg = LineSegment(first: first, startLength: len, x0: x, y0: y - amount,symbol: symbol) + segments.insert(item: .vertical(x: x, y0: y - amount, y1: y, seg)) + y -= amount + + case "D": + let seg = LineSegment(first: first, startLength: len, x0: x, y0: y, symbol: symbol) + segments.insert(item: .vertical(x: x, y0: y, y1: y + amount, seg)) + y += amount + + default: + break loop + } + + len += amount + } while s.scanString(",") != nil +} + +parse(in1, first: true) +parse(in2, first: false) + +var intersections: [(Int, Int, Int)] = [] + +struct Line: Equatable { + var y: Int + let segment: LineSegment +} + +struct Tree { + var items: [Line] = [] + + mutating func add(_ value: Line) { + items.append(value) + } + + mutating func remove(_ value: Line) { + items.removeAll(where: { $0 == value }) + } + + func range(from: Int, to: Int) -> [Line] { + return items.filter({ from <= $0.y && $0.y <= to }) + } +} + +var openLines = Tree() + +var segs = segments +while let s = segs.extractMin() { + print(s) +} + +while let min = segments.extractMin() { + switch min { + case .start(_, let y, let s): + openLines.add(Line(y: y, segment: s)) + + case .end(_, let y, let s): + openLines.remove(Line(y: y, segment: s)) + + case .vertical(let x, let y0, let y1, let f): + print("vertical \(x),\(y0) - \(x),\(y1):") + for l in openLines.range(from: y0, to: y1) where l.segment.first != f.first { + let horizontalDistance = l.segment.startLength + x - l.segment.x0 + let verticalDistance = f.startLength + l.y - f.y0 + print(f, " - ", l.segment, ":", x, l.y, "-", horizontalDistance, verticalDistance, horizontalDistance + verticalDistance) + intersections.append((x, l.y, horizontalDistance + verticalDistance)) + } + } +} + +intersections + .map { $0.2 } + .min() + +intersections + + diff --git a/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Sources/Heap.swift b/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Sources/Heap.swift new file mode 100644 index 0000000..3194619 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/Sources/Heap.swift @@ -0,0 +1,121 @@ +// +// Heap.swift +// SwiftHeap +// +// Created by Sven Weidauer on 30.12.14. +// Copyright (c) 2014 Sven Weidauer. All rights reserved. +// + +import Foundation + +/// A heap +public struct Heap : ExpressibleByArrayLiteral, Equatable { + public typealias ArrayLiteralElement = T + typealias Element = T + + /// Initializes the heap with multiple items + public init(arrayLiteral items : T... ) { + self.init( items ) + } + + public init(_ items: T...) { + self.init(items) + } + + /// Initializes the heap from an array of items + public init( _ items : [T] ) { + self.items = items + for index in (0 ..< size/2).reversed() { + heapify( index ) + } + } + + /// The minimum item on this heap or nil if the heap is empty + public var min : T? { + return items.first + } + + /// The number of items on this heap + public var size : Int { + return items.count + } + + /// true if this heap is empty + public var empty : Bool { + return size > 0 + } + + /** + Removes and returns the minimum item from the heap. + + :returns: The minimum item from the heap or nil if the heap is empty. + */ + public mutating func extractMin() -> T? { + + + if let result = items.first { + items[0] = items[items.count - 1] + items.removeLast() + heapify(0) + return result + } + + return nil + } + + /// Inserts a new item into this heap + /// + /// :param: item The new item to insert + public mutating func insert( item : T ) { + items.append( item ) + var i = items.count - 1 + while i > 0 && items[i] < items[parent( i )] { + items.swapAt(i, parent(i)) + i = parent( i ) + } + } + + /// Restores the heap property starting at a given index + /// + /// :param: index The index to start at + private mutating func heapify(_ index : Int ) { + var minimumIndex = index + if left( index ) < size && items[left( index )] < items[minimumIndex] { + minimumIndex = left( index ) + } + + if right( index ) < size && items[right( index )] < items[minimumIndex] { + minimumIndex = right( index ) + } + + if minimumIndex != index { + items.swapAt(minimumIndex, index) + heapify( minimumIndex ) + } + } + + /// Returns the index of the left child of an item + private func left(_ index : Int ) -> Int { + return 2 * index + 1 + } + + /// Returns the index of the right child of an item + private func right(_ index: Int ) -> Int { + return 2 * index + 2 + } + + /// Returns the index of the parent of an item + private func parent(_ index: Int ) -> Int { + return (index - 1) / 2 + } + + /// Storage for the items in thie heap + private var items : [T] + + /// Compares two heaps for equality + public static func ==( lhs: Heap, rhs: Heap ) -> Bool { + return lhs.items == rhs.items + } + +} + diff --git a/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/timeline.xctimeline b/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/timeline.xctimeline new file mode 100644 index 0000000..b9ada2b --- /dev/null +++ b/2019/AoC.playground/Pages/Day 3.xcplaygroundpage/timeline.xctimeline @@ -0,0 +1,11 @@ + + + + + + + diff --git a/2019/AoC.playground/Pages/Day 4.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 4.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..d829b9d --- /dev/null +++ b/2019/AoC.playground/Pages/Day 4.xcplaygroundpage/Contents.swift @@ -0,0 +1,23 @@ +let min = 172930 +let max = 683082 + +var count = 0 +outer: for i in min...max { + let s = String(i).compactMap { $0.wholeNumberValue } + + var hasDouble = false + + for (first, second) in zip(s, s.dropFirst()) { + if second < first { + continue outer + } + + if first == second { + hasDouble = true + } + } + + guard hasDouble else { continue } + + count += 1 +} diff --git a/2019/AoC.playground/Pages/Day 5.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 5.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..8f7c4ed --- /dev/null +++ b/2019/AoC.playground/Pages/Day 5.xcplaygroundpage/Contents.swift @@ -0,0 +1,98 @@ +let program = [3,225,1,225,6,6,1100,1,238,225,104,0,1002,36,25,224,1001,224,-2100,224,4,224,1002,223,8,223,101,1,224,224,1,223,224,223,1102,31,84,225,1102,29,77,225,1,176,188,224,101,-42,224,224,4,224,102,8,223,223,101,3,224,224,1,223,224,223,2,196,183,224,1001,224,-990,224,4,224,1002,223,8,223,101,7,224,224,1,224,223,223,102,14,40,224,101,-1078,224,224,4,224,1002,223,8,223,1001,224,2,224,1,224,223,223,1001,180,64,224,101,-128,224,224,4,224,102,8,223,223,101,3,224,224,1,223,224,223,1102,24,17,224,1001,224,-408,224,4,224,1002,223,8,223,101,2,224,224,1,223,224,223,1101,9,66,224,1001,224,-75,224,4,224,1002,223,8,223,1001,224,6,224,1,223,224,223,1102,18,33,225,1101,57,64,225,1102,45,11,225,1101,45,9,225,1101,11,34,225,1102,59,22,225,101,89,191,224,1001,224,-100,224,4,224,1002,223,8,223,1001,224,1,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,8,226,677,224,1002,223,2,223,1006,224,329,1001,223,1,223,108,226,226,224,1002,223,2,223,1006,224,344,1001,223,1,223,7,677,226,224,102,2,223,223,1005,224,359,101,1,223,223,7,226,677,224,102,2,223,223,1006,224,374,101,1,223,223,1008,677,226,224,1002,223,2,223,1006,224,389,101,1,223,223,8,677,677,224,1002,223,2,223,1005,224,404,101,1,223,223,8,677,226,224,102,2,223,223,1005,224,419,1001,223,1,223,1107,677,226,224,102,2,223,223,1005,224,434,1001,223,1,223,1107,226,677,224,1002,223,2,223,1006,224,449,1001,223,1,223,107,677,226,224,1002,223,2,223,1005,224,464,1001,223,1,223,1008,677,677,224,1002,223,2,223,1006,224,479,1001,223,1,223,1108,677,226,224,1002,223,2,223,1006,224,494,1001,223,1,223,1108,677,677,224,1002,223,2,223,1006,224,509,1001,223,1,223,107,677,677,224,1002,223,2,223,1005,224,524,101,1,223,223,1007,677,226,224,102,2,223,223,1005,224,539,1001,223,1,223,1107,226,226,224,1002,223,2,223,1006,224,554,1001,223,1,223,1008,226,226,224,1002,223,2,223,1006,224,569,101,1,223,223,1108,226,677,224,1002,223,2,223,1006,224,584,101,1,223,223,108,677,677,224,1002,223,2,223,1006,224,599,1001,223,1,223,1007,677,677,224,102,2,223,223,1006,224,614,101,1,223,223,107,226,226,224,102,2,223,223,1006,224,629,101,1,223,223,1007,226,226,224,102,2,223,223,1005,224,644,1001,223,1,223,108,226,677,224,102,2,223,223,1005,224,659,1001,223,1,223,7,677,677,224,102,2,223,223,1006,224,674,1001,223,1,223,4,223,99,226] + + +func input() -> Int { + return 5 +} + +func output(_ value: Int) { + print("output>",value) +} + +func pow(base: Int = 10, _ n: Int) -> Int { + precondition( n >= 0 ) + switch n { + case 0: return 1 + case 1: return base + case _ where n.isMultiple(of: 2): + return pow(base: base * base, n / 2) + default: + return base * pow(base: base * base, n / 2) + } +} + +func run() { + var memory = program + + var pc = 0 + + func get(_ index: Int) -> Int { + let mode = (memory[pc] / pow(2 + index - 1)) % 10 + + switch mode { + case 0: return memory[memory[pc + index]] + case 1: return memory[pc + index] + default: preconditionFailure("Unknown mode \(mode)") + } + } + + func put(_ index: Int, value: Int) { + memory[memory[pc + index]] = value + } + + loop: while(true) { + let opcode = memory[pc] % 100 + + print("pc", pc, "op", opcode) + + switch opcode { + case 1: + put(3, value: get(1) + get(2)) + pc += 4 + + case 2: + put(3, value: get(1) * get(2)) + pc += 4 + + case 3: + put(1, value: input()) + pc += 2 + + case 4: + output(get(1)) + pc += 2 + + case 5: + if get(1) != 0 { + pc = get(2) + } else { + pc += 3 + } + + case 6: + if get(1) == 0 { + pc = get(2) + } else { + pc += 3 + } + + case 7: + put(3, value: get(1) < get(2) ? 1 : 0) + pc += 4 + + case 8: + put(3, value: get(1) == get(2) ? 1 : 0) + pc += 4 + + case 99: + break loop + + default: + preconditionFailure("Unknown opcode \(opcode)") + + } + } +} + +run() + diff --git a/2019/AoC.playground/Pages/Day 6.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 6.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..6d78386 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 6.xcplaygroundpage/Contents.swift @@ -0,0 +1,1974 @@ +import Foundation + +let input = """ +XV5)LZ5 +6JC)7ZG +NCW)VDZ +CPM)N4Z +3PZ)4D6 +3TT)QPK +G1T)FD5 +S43)3G7 +26J)ZMX +GTS)G9S +1GM)9ZN +WCW)XTJ +9B7)NTZ +QDH)P9B +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DZZ +75P)Z8Q +MP2)VTS +CW7)PZD +GSV)TJJ +5G8)WPZ +45D)RGW +VXC)2YG +GLD)Y35 +L7C)P18 +PSB)PFS +QPM)6R2 +1NB)BKF +787)754 +KRC)B4D +N5Q)DGP +718)B5P +44C)ST4 +XVY)45K +WPB)VSB +PKL)1WV +7DG)37F +QF5)QRB +QC2)MK7 +KPZ)3SC +8M2)LXX +VPZ)45M +V5M)34C +JMQ)ZB6 +B4M)G18 +D6Y)DYT +LFD)B9S +R84)72H +XP4)L74 +H37)BDG +ZTS)NBK +QKC)G3K +7W1)FV4 +16P)M37 +ZSC)XJL +B1D)VBJ +RW8)5X5 +4D2)54L +212)WZG +NY3)TB2 +LR3)6D4 +KYJ)Z52 +9CM)98M +RDB)LHB +W48)V9J +69X)ZFL +45M)NV5 +54Q)QK1 +P18)B38 +QPD)1WG +4DX)9HZ +JC6)598 +LHT)8XB +WKY)VMF +RDV)PMX +XLJ)LRG +MPR)N15 +C9Z)FKC +LZ5)C2K +MW5)TFF +FV4)9BW +2RJ)K8W +9GR)18Y +1LD)JGG +82Z)HKD +7JS)4HT +7NC)CXB +2VZ)YL1 +PQR)JWN +HZP)SV5 +212)42H +QGD)J6P +D5L)6NK +XP7)6TM +18Y)D48 +4TX)4NG +NZJ)ZSC +WGD)QWY +NX4)66X +2MG)BCF +PSV)FVJ +GD7)QC2 +DLZ)542 +2W1)DRN +1WB)P6H +KTF)H5W +Y8J)9ZH +JWB)PYW +1DN)ZG6 +4MX)TSC +5BF)PYB +SLL)KSW +RGR)4CS +9T1)T26 +7H9)3SR +BRP)TD9 +B73)C5P +BXK)VN8 +4KT)6X5 +B65)BTV +N88)2V5 +P2F)6SB +PYW)QTV +MJY)684 +JSF)P77 +LP4)P4J +LKF)RNH +SSB)3VB +D75)F2D +SD9)HDZ +S46)1L7 +QYY)638 +XJJ)HJT +R5D)Y72 +TXH)VN5 +WLD)HT2 +DLC)36P +WS3)XLF +HKD)V9F +CKB)2YZ +57X)RX9 +YK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 +B73)B5R +9L7)1JK +3G5)P7C +B8P)BB7 +6G7)K2H +598)V3L +QBZ)BR7 +GQ5)HYW +RLH)DCD +BD9)CMV +N34)J18 +3V7)KFR +6N8)4J3 +J6H)QHN +JGG)F6G +WJ6)X5S +KSJ)D81 +662)VCV +4XT)B1J +JWB)SXX +XN6)XLJ +LFH)TFP +RT8)Y5D +QKY)LY5 +PYB)FD7 +F1F)WDL +CWM)RL5 +RR8)C8B +18B)PWN +F35)3HS +B9S)7D4 +5BD)X79 +TGJ)9HF +NNJ)235 +DTH)NDS +GLL)CPY +138)RXP +X9Q)LHF +WNV)DF5 +19N)46N +QKV)BYV +7TH)JNR +GL3)288 +66Q)YYR +SK4)4VH +QNJ)XQZ +7CC)278 +BDG)T8D +WBM)YMW +NCW)RHM +2V7)YGW +PYB)XSG +RX9)YMP +BCY)J1N +JZ8)5CZ +362)QVX +517)QPM +K74)3WF +G9V)MHQ +Z8Q)CJ2 +69M)54X +STB)CHC +VSW)GWD +CMV)XTB +17H)XNF +CXG)HNZ +HNR)LVJ +S5B)QJR +Z73)6MM +WQT)7QR +P6H)VHY +BZ4)B33 +NM6)DKD +9KV)419 +235)G2V +K71)6MW +T8Q)Y62 +68B)Q3S +8MG)68B +FSQ)3GM +4XF)WJD +FG6)36B +DYZ)XDF +BX4)XV7 +77F)WQR +JTC)HTJ +YZC)MVQ +LM8)2B6 +ZB6)SXP +PXC)5TP +F6G)5FM +G18)4WQ +R4M)HFX +HMP)2QP +Q1L)2RJ +QRB)9G5 +YJZ)STB +3FH)3K3 +356)DKJ +5GR)27Y +BNQ)NC3 +36P)G7T +YN2)HYX +P76)39D +PJS)YQX +C76)C1P +27Y)65Z +HVY)37H +462)16P +N8L)Q44 +FQM)BWD +54L)DQH +455)P1T +5GF)6JL +JWR)WFT +FG7)H2M +DBT)J9B +Q72)6KN +756)BNQ +MQG)HNR +HDV)VGH +FKM)MXF +6PM)V7Q +HPC)QWD +G5M)Z1T +FRD)8ZS +ZPH)7TK +K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53H +Z3C)LT3 +VDN)GRY +6JL)9Z9 +7NF)PML +14T)WSX +1V9)N7N +N3V)HPD +F53)PPJ +DQ9)TNL +JPH)1FL +L1C)WBS +RMY)BMJ +MV1)1CP +4GY)8M8 +CGN)4GC +7B1)26V +8QN)JSG +VQC)XRT +J1N)MKN +PYS)289 +7Z9)HDV +SJB)4C6 +LX3)HX7 +94G)R1P +DY7)D6W +3FH)2RV +XKS)WHK +FNB)6L2 +K6Y)NK7 +BYV)Z9F +QBZ)FVB +C5B)73F +6SC)DMP +B5R)K3N +BKV)YKB +VW8)1FD +PWN)QPL +DG5)BQH +1MD)YCZ +KWK)CZ9 +JY5)NX4 +F2T)8QR +RYS)KF3 +LRM)M1W +LXX)CD1 +98M)J4X +D6Y)M17 +97S)BSK +X11)2X9 +WKP)57B +CCX)221 +GJM)T5M +LT9)7YP +RVW)FZP +62K)CLV +3VL)QQK +3XD)HQ5 +W3R)QFC +8JW)32H +KCD)2HC +SND)9FD +4PR)D3D +Q68)77F +56P)87R +SD1)RHS +COM)2WF +Q53)HBT +ZJ5)68M +4VH)VDN +Z36)2QN +FD6)R96 +NWP)HZP +4T6)LGZ +QTV)GF6 +S2P)HZ6 +XFC)S8R +2V5)QDH +PPQ)CD6 +Z71)YKH +RYK)864 +VMF)MZQ +KZK)KTF +KZK)XKS +SLK)WBM +HWZ)CX5 +N1L)2HF +54X)JWR +TYF)YY5 +3DM)264 +FLG)FBP +D2J)376 +2RV)JPH +PMX)12Z +CLB)7TS +CNC)RCK +281)8M2 +2SB)R4M +KF3)1RN +B38)4FG +GV9)XV5 +33M)676 +QGN)HS2 +7D4)GFY +4CT)STK +N15)R1V +29B)Q4W +DXZ)BV8 +563)GLX +XDF)GRS +1LQ)TK5 +BPW)C93 +KP7)GLH +2X2)F24 +YTR)LT9 +MN2)NNP +W7K)TF6 +DGK)KPN +D6W)PVB +67R)3DJ +TB6)NLV +MDR)PLQ +C92)3NQ +F8D)1P3 +4ZK)T9B +347)JJY +XNF)6H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N3 +LXM)P76 +42H)9W9 +CCD)W8T +176)S7S +B41)G6R +KLZ)P19 +SQ6)XFC +TF6)H89 +2FV)8DB +4Y2)4D2 +JTF)TKW +LDQ)X6L +LT3)T3K +QK1)GB4 +W4N)7Z9 +BKM)7CC +65H)S2P +8K9)YJZ +253)9WY +KVN)4PP +2Z4)F3G +C93)KTW +5FM)QSW +F24)4DX +T3K)NR8 +3G7)RKY +V73)6MV +BT3)2F1 +HLY)CCD +GLH)94G +2CZ)W2J +NSK)NC8 +V5H)M41 +19X)NXV +QMQ)54Q +LRG)Q48 +7CQ)YB2 +TSF)8XQ +FCS)2VF +16V)VXC +HBZ)WGD +VJV)JY5 +XRT)J2X +424)5GR +SXB)XJP +BJC)5PJ +SND)49C +LC1)8Y7 +FR7)L6J +H2M)XHR +BW2)C9Z +2HW)185 +TYL)2K5 +15P)6HZ +LK7)YZ8 +JPZ)NNJ +NGS)G3S +GL5)QVR +DJH)NZ6 +GKB)9S3 +JCX)Z42 +P2S)T92 +9ZN)ZCY +PY6)DVV +YP3)W5Z +11M)WQT +PQ9)G3Z +2S1)SPV +CQX)ZQF +YPZ)LQ9 +VRQ)TZ9 +GY8)26X +985)YQ3 +9ZP)9RP +9JW)VL1 +4MX)33M +L6J)L3S +KBG)P3N +G22)RPQ +948)1FS +3KS)CW7 +WCV)WNV +LB9)KL3 +BDT)21H +Q53)VB9 +HCV)2CZ +7RX)TQM +4GC)LDV +PL9)N2M +1VY)NL2 +R96)153 +37F)53G +VT1)KF4 +61T)838 +HBT)R4N +H81)TB6 +1FL)FR7 +J65)D9Z +8Y7)22J +KZ3)JFL +W5B)B9W +G27)QJ7 +V72)1MD +5G8)J12 +T39)STH +6JL)HCV +SK4)K6Y +Z1T)2FV +PPJ)LJW +JKJ)64J +47Y)QGH +N1V)CVT +PJQ)TWQ +26V)QMC +5Y3)1QR +F1W)VXM +49S)QKP +""" + +class Node: Hashable { + let name: String + + init( name: String) { + self.name = name + } + + weak var parent: Node? + var children: Set = [] + + func countOrbits(parents: Int = 0) -> Int { + return children.reduce( parents ) { $0 + $1.countOrbits(parents: parents + 1) } + } + + func hash(into hasher: inout Hasher) { + hasher.combine(ObjectIdentifier(self)) + } + + static func == (lhs: Node, rhs: Node) -> Bool { + return lhs === rhs + } + + func addChild(_ node: Node) { + children.insert(node) + node.parent = self + } + + func hasChild(_ node: Node) -> Bool { + return children.contains(node) + || children.contains(where: { $0.hasChild(node) } ) + } + + func distanceTo(_ node: Node) -> Int? { + if children.contains(node) { + return 0 + } + + for child in children { + if let distance = child.distanceTo(node) { + return distance + 1 + } + } + + return nil + } +} + +var nodes: [String : Node] = [:] + + +let s = Scanner(string: input) +s.charactersToBeSkipped = nil + +func getOrAdd(_ name: String) -> Node { + if let node = nodes[name] { + return node + } + + let new = Node(name: name) + nodes[name] = new + return new +} + +repeat { + guard + let first = s.scanUpToString(")"), + s.scanString(")") != nil, + let second = s.scanUpToString("\n") + else { + fatalError() + } + + getOrAdd(first).addChild(getOrAdd(second)) + +} while s.scanString("\n") != nil + +nodes["COM"]?.countOrbits(parents: 0) +nodes + +let you = nodes["YOU"]! +let santa = nodes["SAN"]! + +var count = 0 + +var common: Node? = you +while let next = common, !next.hasChild(santa) { + common = next.parent + count += 1 +} + +guard let common = common else { + fatalError() +} + + + +common.name + +count + common.distanceTo(santa)! + diff --git a/2019/AoC.playground/Pages/Day 7.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 7.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..96133c1 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 7.xcplaygroundpage/Contents.swift @@ -0,0 +1,115 @@ +import Foundation + +let program = [3,8,1001,8,10,8,105,1,0,0,21,38,59,84,93,110,191,272,353,434,99999,3,9,101,5,9,9,1002,9,5,9,101,5,9,9,4,9,99,3,9,1001,9,3,9,1002,9,2,9,101,4,9,9,1002,9,4,9,4,9,99,3,9,102,5,9,9,1001,9,4,9,1002,9,2,9,1001,9,5,9,102,4,9,9,4,9,99,3,9,1002,9,2,9,4,9,99,3,9,1002,9,5,9,101,4,9,9,102,2,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,99,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,99,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,99] + + +class Io: IO { + var inputs = [4, 0, 3, 2, 1, 0] + + func input() -> Int { + let input = inputs.remove(at: 0) + return input + } + + var lastOutput = 0 + func output(_ value: Int) { + lastOutput = value + if !inputs.isEmpty { + inputs.insert(value, at: 1) + } + } +} + +class Buffered: IO { + var inputs: [Int] = [] + let condition = NSCondition() + var outputHandler: (Int) -> Void = { _ in } + + + + func input() -> Int { + condition.lock() + defer { condition.unlock() } + + while inputs.isEmpty { + condition.wait() + } + + return inputs.removeFirst() + } + + func add(input: Int) { + condition.lock() + defer { condition.unlock() } + + inputs.append(input) + condition.signal() + } + + func output(_ value: Int) { + outputHandler(value) + } +} + +func test(phases: [Int]) -> Int { + + let ios = phases.map { phase -> Buffered in + let b = Buffered() + b.add(input: phase) + return b + } + + ios[0].add(input: 0) + + for i in 0 ..< ios.count - 1 { + ios[i].outputHandler = { [unowned next = ios[i + 1]] val in + next.add(input: val) + } + } + + var lastOutput = -1 + + ios[ios.count - 1].outputHandler = { [unowned first = ios[0]] val in + first.add(input: val) + lastOutput = val + print("out>", val) + } + + let group = DispatchGroup() + + for io in ios { + DispatchQueue.global().async(group: group) { + IntCode(program: program, io: io).run() + } + } + + group.wait() + + print("done>", lastOutput) + print("\n\n") + + return lastOutput +} + +var maxOutput = Int.min +var maxPhases: [Int] = [] + +for a in 0...4 { + for b in 0...4 where b != a { + for c in 0...4 where c != b && c != a { + for d in 0...4 where d != c && d != b && d != a { + for e in 0...4 where e != d && e != c && e != c && e != b && e != a { + let phases = [5 + a, 5 + b, 5 + c, 5 + d, 5 + e] + let output = test(phases: phases) + if maxOutput < output { + maxOutput = output + maxPhases = phases + } + } + } + } + } +} + +maxOutput +maxPhases diff --git a/2019/AoC.playground/Pages/Day 8.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 8.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..91c41d7 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 8.xcplaygroundpage/Contents.swift @@ -0,0 +1,27 @@ +let input = "221202222022222022021222222222122202202222222122002202221222222222202022202222222222222222222222022222022202221222022222222202222212202222202202222222220212222222222222122222022222022212222222222122002212220222222222202122222222222222222222222222022222022222221222022222222222222202202222212222222222222222222022222122022222122222022212202222222222002222222222222222222222222222222222222222222222222222222202222222022222222202222222002222212212222222220202222222222022121222122222122222212222222122112202220222220222212222202222222222222222222222022222222202222222222222222202222202102222202222222222221202212222222022222222222222022212212212222022202201222222222222212222202222222222222222222222222222222212220222222222222202222222122222212202222222220202222122222222220222122222122222202212222222222202221222220222212122212222222222222222222202222222222222220222022222222222222222222222222222222222221202222122222022222222222222222222202212222122122210222222220222222122222222222222222222222222222222122222222222122222222202222222002222202202220222220202212222222122120222122222222202222202222022012221220222222222202022212222222222222222222222022222222222220222022222222212222222202221202212222222222202222122222122021222122222122222222222222222202200222222222222202022212222222222222222222202122222122212221222022222222212222202122222212222220222221212202222222222121222222222022212222202222022222220221222221222202122212222222222222222222202222222122222222222022222222222222202122222212202221222221202212122222022221222222222022202202222222022011220220222222222202022202222222222222222222222222222222222220222122222222212222212112222222202220222221212222122222022020222022222120222202212222122202221220222222222222022222222222222222222222202222222022202221222022222221202222222222221212222222222221212212022222122020222222222021212212222222222120201220222221222202122202222222202222222222222022222022202221222022222221222222212122222212202220222220222202122222122020222122222220202202212222022000210221222220202202122202222222202222222222222022222022212221222022222220202222202102222202222220222221202222122222222220222022222121202212202222222120212221222222212222122222222222212222222222202222222222222222222222222221212222212002221202222222222221212212022222022122222122222122222222222222222110222222222220212212122212222222200222222212222222222122222222222022222222212222212002222222222220222221212202122222122022222222222121212202222022122120201222222220212222221212222222201222222202202222222022222221222122222220202222212102220202212222222222202202222222122121222122222121212202222122222010200021222221222212121212222222221222222222222122222122212220222222222221212222202002222222222222222221222222222222122121222222222020222212202122022201220120222220222212220212222222210222222222212222222022202220222222222222202222212012222221222222222222212212022222212221222012222220212222212222222200212220222220222222022202222222202222222222202112222022212222222022222222202222222122221222212220222220212212222222112022222002222121202202222022022212200220222220202212222212222222212222222212212122222222202221222022222222222222212022221201212221222220212212122222202022222022222122222212222022022122202220222220222202220222222222211222222222212222222022112221222022222221222222212102220221222220222221222212122222002121222012222122212212212122122120200122222221221222222202222222012222222222222022222122002220222222222220212222202212221212222020222220202222002222022221222102222022222222222122202111201022222222210212222212222222012222222222222100222222122220222122222221212222222002221200202221222222202202002222012020222012222120202222202222112021200220222220201222021222222222222222222212222021222122012222222122022220202222202012220212212121222222212202102202002021222212222222202222202022202210222020222201222202220222222222200222222212202120222122102221222022222220212222222002221222212220222220202222222212222121222212222021222212212022102121201021222202220212122202222222000222222212212010222122102221222022022220212222222102220220222021222220202202212222222222222222222122212202212222212200200121222200220222221222222222001222222222122100222222122220222122222220212222212102220210202222222222212222102202212221222212222222212212212022022202210021222222201212021212222222102222222212122221222022002222222022122220222222202002220212212221222221202221102212212222222222222022202222212222102102221022222200211222021222222222110222222212122220222122202221222022022221212222202212221201212020222221222210002212011122022112222120212222212022202210210022222200212222221202222222200222222222002112222222202220222022222221202222202002220212202020222222221210022212122120022112222121222222202122112200201121222201211212122222222222212222222222012212222122022222222222022220222222222022222210222122222221222222202212122021022022222021222202202222002210211221222210222212221212222222121222222202122010222022222222222022022220202222222002222222222211222220212210112222010222022112220021212202212122122011202122222220211222220202222222022222222222002112222222212220222022122220202222222112222222222102222220210220002222012120022212222122202202222122212110211020222221202212020222222222002222222222102112222122202220222122022221222222212002222220222100222221200222022202211021222222222122202202222122102020222020222202222222220212222222012222222222202202222122222220222222022222222222222222220201202010222222201221012222220121022202221121222222202022222020210121222200211212220202222222222222222222012002222122212221222222022221212222222222221200202102222221221221222210110222122012222222202222202022102200222222222210220212121212222222121222222202012112222122122222222122022221202222212202222201202002222222211210112222001022222222221020222212222220102221222220222200202212120212222222102222222222202101222122002222222022222220202222222022220212212020222222212200122220001121022112220122202212222120112211220121222201022222022220222222001222222202202101222122012221222022022221202222222212222212202000222221012201102221200120022022222220202202222121002101201020222211111212020212222222110222222222102222222222202222222222222220202222202102222201202020222222212210022222001121122220221120222212202022202202220220222211022202020210222222220212222222212202222122122220222122222222202222212222222210202012222220011211122221010021021000222222222212202220112000221222222220221202222221222222212202222212112001222222112220222122222221202222222122220001222210222220012202122220021020220121222122222202202222122012210120222211002212020200222222100212222202012201222122222222222022122222222222212002222121222100222221101211012201221222020221220220202202212021202220220020222211002222222201222222211202202222012111222022112222222022022221222222212212222210222210222221101212012202211022021102220020222222202021122000200021222200010212122220222222001202202202212001222222002222222022022220212222222102221200202021222221212201122212122021021011220220212212202021002022212020222222212222122201222222121212212212022110222122002221222222022220222222212122222002222002222222202200112202220122021112221121202212222220022021211220222210122222121212222222121202212202012222222222212222222222122221202222222202220112202010222220101211222202021222022012222222222222222020022221212120222221101202021222222222211222212222112110222022122221222022222222212222222022221211222222222221101221122202220220022121222120202222202221122010210122222222001222222221122222021212212202012221222222012220222022122220202222222222221222212111222222222200202222211222021112222022202212202221022000202220222212100222022201122222210202212222102201222022122221202122222221212222212012221121212102222220212220112221000222120022220120222202222022112102201120222221222212021222122222101222202222222011222222212220202222222220212222222122222210212002212220222222202222110022222102222120212202202120012122211220222200200202022222222222210222202202112110222222212221222022122221212222222112222012212220222222222211022200122221220212222221212202222122202112212022222212201202022211122222201222222212112121222222022222202222022220201222212112222012202012222220022200002211010121022112222122222222202222022001221122222210210202021200122222222202212201202102222022202221202222022220222222212202221101202200212221020211102212022122120111221021212212222020112120200022222222221212221202022222000222212211012020222022102222222222222220212222222002220222222222222222022200222202122021120000220220222222202021022000201020122211011222021221022222012212222222112220222222122222202022222220222222212022221111212002212222110210022221100222120210221220222202202211222011222222122221010222121201022222211202212202012102222122122222222222122221221222212122221012212011222221201202022210012021220220222222221202202100122012220020222202210212222211022222110202222201022000222122012221002122222221200222202202222100202221222222021200012200111222021112221222221212212012212110211020022221010202120222022222220212222201012012222122022220002222022221202222202000221212222001202220001201112202202022121211220021211002212222012222222021122121012202021200122222110202222221212202222222012220102122122220220222202002221211212112212221120200022200102022021210221022210012202101202212222120022222012212022211222222012212222221112002222022012222002022122221220222022202221212202102222220000220112220210221022010220020202002202102222011201220022002102222021212122222001222202222202202222122122222222022022221220222112010221110212220212220101221202201000120220211222022220122222000022000200022122102012222221222222222020212212112012020222122122220222222022222200222202121220001212011222220021211222200002020121010221122212022222010111202210220122121220202120210122222120222222122012220222222022221022020022222220222022010220111222112202221120100002221220120021010222022220222212222002102200221022110221012221222022222210222202202102200222122102220212121122222201222202121221021212111212220100010012221211122020100221121201122212110020121221121120001122222021220122222110202202121112002222222012221002022022221201222112112221102212222202222112011002201000120121102222222220212222221202000210220221121010022020201222222002202212001112002222122002221122220222221202222112221221020202000202222020121112210210122120212220221202012222220020011202020220112100212020220122222012202212000022122022122102222122120022220210222002220222011202210222221211201202212111122122221220122211022202211121202200121222212010122121210022222121202202100202101222122202221112120022222200222122100220111202211212220120110102221201121022220222022220202222122200212221121020011011012021222222222220222202001112000022022022222102020022220222222122122221111202212212221102100202202110022120022222121202002202200210111222222121111121202020201122222120222222212122202022122222221112121022221221222002220220222222201212222211010002220220122220020221021222012202202220211222120021001112122020220222222100222212011012121012122222220122222122220200222212021220212012212222222200012122211112222122000220221221021222220202012201211021211211002220212222222212202212212222110022122202220112222022220211222112011221001122002202222220122012211201122121210220120211012202212011221211020121101000022122222122222012222222212212221212022202222202021122222221222002012221211222202202220120222112210101120221102220021212221222220011110201220121100010122022221022222112212212001102221202122102222102021022222202222022210220220212202212222021011212222020220022021222020201110212001120122212001121202110122221212022222221212212012011011112022202220012220222220221222212021221102102212222221101211002222211122221022220021202102202222021211212012221011020102020222122222101222212111111210212022122220112110222220221222002202220001202212212221220210122210021020122220220022200010202222112021210002120001102202022220122222122202202211002001222222112221122201022220220222102212221220202112212220012120222212021120020022221022211201212221222202202200222202000112021210022222101222012022202102012222002222102022012220220222222020221110222212212221122222012222010221122021222220220110212001111210222022120021012222022200022222000200010220100212112022022220112221202220220222112212222200112110202222022221012210111100121020220121222020022001102202201010220122200202120202022222011220001220121000022222002220202121222120220222112112222100112221212221210210022212020011220202220022221010112222210212202111122202121122222222122222220210222120210200202222212221201122022021221222100021220200102220202221012112212211201121122221211121212002212100211022221101120221002202111201222222111222222021121221002022022222211221102021220222101022220101022121212222210220022202010221220001222022211102112221012010200002022022011212021201122222122210011121220001202122122221010101102120210222210121221012012211212220102001022210102201120012212022011201112022012222220122020100221222011021122222222210001221002122012122112220122220212221202222202112221121111112202222212120012222200220121222221020022112112212210011212200002211112122200222122222122222100022202200222222012221120220222020220222121102220021022200212221112011012210212100020010220220100021112020121001222000110221012112100201122222100222122122201110012222212221221122022120220222212201221200022010222220100120012212200210121202210120001111022202010010210221012212200112102000222222112222122220111212102122122221222120222020210222100020211012000121202222202021202120001122022011202022221002122120100020212022000021001102122222022222020211012212102210112022122220011201220221200222010000211201211221212220211200012201100101120122210022100122222101200002210122200201120022122021122222210222020011210010222122122221001011202221210222111102202122100220222220100020112101200221121222200220012022212022210221211120100220022202120122022222200202001122212010222222102220210020110220201222002112222012200010212222121202202211020200221220220222002102202220000111212101002112111102101222222222020221120201101220002222112221210001221021210222102120221112201121212222220022222101011121122200222122110022022121202002210002211012110102110020222222110221001100220021102022202221110102121220200222020212211101012112202221200211212112201201021001222022012021222010000221220010222012220012020201222222011220100111020202222022202222100012102220211222100111210012020022222221000112022001201122020021201222112122122012100200220210100211222222222212022222202222112111120101002022012220112022022021201222021021201211102021222220112112112211020222200100210222120020112202100002022001212122120022012010022022122202000201111001022222102221101212122020220222212002201112201211212220011020202010210220021102202220101212202110020200001011210220010122022001022222022222111210200100222122212222212202022222220222212220220220221211022221000212202121010120112211211020201001212202211000221112100122011202012202122022112200220201212011112022212222121212101220212222121002200102200222022110212210021212111120200110002102100002120001211101220211022221012021211101111001110020002010110001220000000000010122211201020000101211002111121122220" + +let layerSize = 25 * 6 + +var layer = 0 + +var indexInLayer = 0 + + +var result = Array(repeating: " ", count: layerSize) + +for ch in input { + + let index = result.index(result.startIndex, offsetBy: indexInLayer) + if (ch == "0" || ch == "1") && result[index] == " " { + result[index] = ch + } + + indexInLayer += 1 + if indexInLayer == layerSize { + indexInLayer = 0 + } +} + +for i in 0..<6 { + print(String(result[i * 25 ..< (i + 1) * 25].map({ $0 == "1" ? "*" : " "}))) +} diff --git a/2019/AoC.playground/Pages/Day 9.xcplaygroundpage/Contents.swift b/2019/AoC.playground/Pages/Day 9.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..9afe869 --- /dev/null +++ b/2019/AoC.playground/Pages/Day 9.xcplaygroundpage/Contents.swift @@ -0,0 +1,16 @@ +let program = [1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1102,3,1,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1101,0,33,1017,1101,24,0,1014,1101,519,0,1028,1102,34,1,1004,1101,0,31,1007,1101,0,844,1025,1102,0,1,1020,1102,38,1,1003,1102,39,1,1008,1102,849,1,1024,1101,0,22,1001,1102,25,1,1009,1101,1,0,1021,1101,0,407,1022,1101,404,0,1023,1101,0,35,1013,1101,27,0,1011,1101,0,37,1016,1102,1,26,1019,1102,28,1,1015,1101,0,30,1000,1102,1,36,1005,1101,0,29,1002,1101,23,0,1012,1102,1,32,1010,1102,21,1,1006,1101,808,0,1027,1102,20,1,1018,1101,0,514,1029,1102,1,815,1026,109,14,2107,24,-5,63,1005,63,199,4,187,1105,1,203,1001,64,1,64,1002,64,2,64,109,-1,2108,21,-7,63,1005,63,225,4,209,1001,64,1,64,1106,0,225,1002,64,2,64,109,-16,1201,6,0,63,1008,63,35,63,1005,63,249,1001,64,1,64,1106,0,251,4,231,1002,64,2,64,109,9,2102,1,2,63,1008,63,37,63,1005,63,271,1105,1,277,4,257,1001,64,1,64,1002,64,2,64,109,11,1208,-8,23,63,1005,63,293,1105,1,299,4,283,1001,64,1,64,1002,64,2,64,109,8,21107,40,39,-8,1005,1017,319,1001,64,1,64,1106,0,321,4,305,1002,64,2,64,109,-28,2101,0,6,63,1008,63,39,63,1005,63,341,1106,0,347,4,327,1001,64,1,64,1002,64,2,64,109,19,2107,26,-7,63,1005,63,363,1106,0,369,4,353,1001,64,1,64,1002,64,2,64,109,1,1202,-9,1,63,1008,63,39,63,1005,63,395,4,375,1001,64,1,64,1105,1,395,1002,64,2,64,109,9,2105,1,-3,1106,0,413,4,401,1001,64,1,64,1002,64,2,64,109,-13,1207,-4,26,63,1005,63,435,4,419,1001,64,1,64,1105,1,435,1002,64,2,64,109,-1,21101,41,0,7,1008,1019,41,63,1005,63,461,4,441,1001,64,1,64,1105,1,461,1002,64,2,64,109,7,21107,42,43,-2,1005,1017,479,4,467,1105,1,483,1001,64,1,64,1002,64,2,64,109,-6,21108,43,46,0,1005,1013,499,1106,0,505,4,489,1001,64,1,64,1002,64,2,64,109,17,2106,0,-2,4,511,1105,1,523,1001,64,1,64,1002,64,2,64,109,-27,1202,-1,1,63,1008,63,28,63,1005,63,547,1001,64,1,64,1106,0,549,4,529,1002,64,2,64,109,18,1206,-1,567,4,555,1001,64,1,64,1106,0,567,1002,64,2,64,109,-16,21102,44,1,6,1008,1011,43,63,1005,63,587,1106,0,593,4,573,1001,64,1,64,1002,64,2,64,109,8,21102,45,1,-1,1008,1012,45,63,1005,63,619,4,599,1001,64,1,64,1105,1,619,1002,64,2,64,109,7,1205,1,633,4,625,1106,0,637,1001,64,1,64,1002,64,2,64,109,-8,2102,1,-3,63,1008,63,25,63,1005,63,659,4,643,1105,1,663,1001,64,1,64,1002,64,2,64,109,14,1206,-5,679,1001,64,1,64,1105,1,681,4,669,1002,64,2,64,109,-28,2101,0,2,63,1008,63,30,63,1005,63,707,4,687,1001,64,1,64,1106,0,707,1002,64,2,64,109,21,21101,46,0,0,1008,1019,48,63,1005,63,727,1106,0,733,4,713,1001,64,1,64,1002,64,2,64,109,-3,21108,47,47,1,1005,1017,751,4,739,1106,0,755,1001,64,1,64,1002,64,2,64,109,-13,1207,0,37,63,1005,63,771,1105,1,777,4,761,1001,64,1,64,1002,64,2,64,109,7,2108,21,-9,63,1005,63,797,1001,64,1,64,1105,1,799,4,783,1002,64,2,64,109,22,2106,0,-5,1001,64,1,64,1106,0,817,4,805,1002,64,2,64,109,-4,1205,-8,829,1106,0,835,4,823,1001,64,1,64,1002,64,2,64,109,-4,2105,1,0,4,841,1105,1,853,1001,64,1,64,1002,64,2,64,109,-30,1208,6,30,63,1005,63,871,4,859,1105,1,875,1001,64,1,64,1002,64,2,64,109,-2,1201,9,0,63,1008,63,22,63,1005,63,897,4,881,1106,0,901,1001,64,1,64,4,64,99,21101,27,0,1,21102,1,915,0,1106,0,922,21201,1,66266,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21102,942,1,0,1105,1,922,22101,0,1,-1,21201,-2,-3,1,21101,0,957,0,1106,0,922,22201,1,-1,-2,1105,1,968,21202,-2,1,-2,109,-3,2106,0,0] + + +class io: IO { + func input() -> Int { + return 2 + } + + func output(_ value: Int) { + print("output>", value) + } + +} + +IntCode(program: program, io: io()).run() + diff --git a/2019/AoC.playground/Sources/IntCode.swift b/2019/AoC.playground/Sources/IntCode.swift new file mode 100644 index 0000000..8a76ff4 --- /dev/null +++ b/2019/AoC.playground/Sources/IntCode.swift @@ -0,0 +1,118 @@ + + +func pow(base: Int = 10, _ n: Int) -> Int { + precondition( n >= 0 ) + switch n { + case 0: return 1 + case 1: return base + case _ where n.isMultiple(of: 2): + return pow(base: base * base, n / 2) + default: + return base * pow(base: base * base, n / 2) + } +} + +public protocol IO: class { + func input() -> Int + func output(_ value: Int) +} + +public class IntCode { + var memory: [Int] + + var pc = 0 + var base = 0 + + var io: IO + + public init(program: [Int], io: IO) { + self.memory = program + self.io = io + } + + func address(_ index: Int) -> Int { + let mode = (memory[pc] / pow(2 + index - 1)) % 10 + + switch mode { + case 0: return memory[pc + index] + case 1: return pc + index + case 2: return memory[pc + index] + base + default: preconditionFailure("Unknown mode \(mode)") + } + } + + func get(_ index: Int) -> Int { + let addr = address(index) + return addr < memory.count ? memory[addr] : 0 + } + + func put(_ index: Int, value: Int) { + + let addr = address(index) + + let toAdd = addr - memory.count + 1 + if toAdd > 0 { + memory.append(contentsOf: Array(repeating: 0, count: toAdd)) + } + + memory[addr] = value + } + + + public func run() { + loop: while(true) { + let opcode = memory[pc] % 100 + + switch opcode { + case 1: + put(3, value: get(1) + get(2)) + pc += 4 + + case 2: + put(3, value: get(1) * get(2)) + pc += 4 + + case 3: + put(1, value: io.input()) + pc += 2 + + case 4: + io.output(get(1)) + pc += 2 + + case 5: + if get(1) != 0 { + pc = get(2) + } else { + pc += 3 + } + + case 6: + if get(1) == 0 { + pc = get(2) + } else { + pc += 3 + } + + case 7: + put(3, value: get(1) < get(2) ? 1 : 0) + pc += 4 + + case 8: + put(3, value: get(1) == get(2) ? 1 : 0) + pc += 4 + + case 9: + base += get(1) + pc += 2 + + case 99: + break loop + + default: + preconditionFailure("Unknown opcode \(opcode)") + + } + } + } +} diff --git a/2019/AoC.playground/Sources/Tools.swift b/2019/AoC.playground/Sources/Tools.swift new file mode 100644 index 0000000..fab9617 --- /dev/null +++ b/2019/AoC.playground/Sources/Tools.swift @@ -0,0 +1,28 @@ +public struct Array2d { + public let width: Int + public let height: Int + private(set) public var data: [T] + + public init(initial: T, width: Int, height: Int) { + precondition(width > 0 && height > 0) + + self.width = width + self.height = height + data = Array(repeating: initial, count: width * height) + } + + public subscript(pos: (Int, Int)) -> T { + get { + let (x, y) = pos + precondition(0..6(31gkaW@+X0n@! zN`L3Q`}Rv(LYqwchNu5K_nv#sx#ymH?tO1B|MasT|JOpL9EwZ+tmdw9^2f!^wUWDY zj`=w2pRK~cwN=`1ovX2M9w7HU7OA}6SYRlo3Bc>^c&4)>Puox5t+t*-UImXoaVhn? zQZz@62-ug`>yO4F!Elc*D3$lImh&gN-nm9ZS)T-2`$fV^gZMmRQKlP<(YY+zy0B8 z-hrj|oz?PQ*R9f8-VpM%D}I5zV*9qRb{^&8+Tsc#w>2nGG7b3B2_(V$=E zj9jzm6PtELd;`5ff3%z*ig?P%+0*uHFqbfGJtcPKc*^*@xj)n&@eGIkrm+R~mdcTN zwufLWD<={t>UbG@JOTe;Bp4eu<&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qp=@t@T+AD7McCpEo6(-$91<~lBS2mAI6A!Tl?dn_yhW+rcda4 zd%n(NyruqkbbSy0rAxW%2K_IjBPI2(mDJZGzmWe+__vV$Ir<9eZ%tcOL1Evqp&@0R zwf6P|VjY~GeR{Z+k0*Rkd5%+#d&15AeEi_#Sy=&5>a>KNZSBp^cw5?`%QQUX z33@%jm^bDR!d2G%qH~QQ&fG@&AL|Yr4Mt**aoWA7ClD#C;+TKn4uT5~gx*(K z&S1;Y)&8*eXdn`m6RvpC-+Lq)JL2uOj;)rLs?W7*S%)IQ?w){k7PdVQ^Ks&}+-S9$ zRn~Vd{toT(bVm1wh@RoTL;V~lb@9=wY}=p;c|)P2eb$FOIafUx3V8L|YV+fscV_hD zj=Gi;ixHvyZ5+=o6Wvc*UywY(qdjGLHk;p??#NOQQ|09p#+1n=LFftkgAi5+?>NEs zgj;dH8N4y3fZe8ed_n% zigIIO&S<80K9}5qxp4m6ZJT_=-)#%g@;`57&4atuVTa<~^5;*N-)#%d6PK{|`9h(7 zzXYy5-C7H%mi8|b`-jTL^)ddxiylQ&4negm5Dr9w{(ZjCV8D(xn};~i)%hAb3JT(E z22Yupcg&A=F}&46pM|roK~`0C$Z0F&o4N~bpJm@u*c1EAs6btkRX*cBEY<~Cu;+JDP571XTS22gYUe~PV zl=bNTePyfiiDsa+JXbE&+=;0m*=ROT(9;s#zqhRN*78-yn$0>-@VT{$q#_Fj!4_+#w}i7G#ZG=inf#Aat0%T!qMM+ zIOOYzMmIkfV6|&29e)PCX}4!E`sDL_!m%ed?ThXF707JbG*e`uCvw}TR#ThRm)0Go z_clo&Hk*&Wry_xY0KppW+3e@nrm@mE)-Hqi#VaAtfbH?-C)%L1%2DNLB@a9!7Z9@ RkMZN=U|-;|4ff9dzX3TDI7$Ej literal 0 HcmV?d00001 diff --git a/2019/AoC.playground/Tools.remap b/2019/AoC.playground/Tools.remap new file mode 100644 index 0000000..32960f8 --- /dev/null +++ b/2019/AoC.playground/Tools.remap @@ -0,0 +1,2 @@ +[ +] \ No newline at end of file diff --git a/2019/AoC.playground/contents.xcplayground b/2019/AoC.playground/contents.xcplayground new file mode 100644 index 0000000..02b9ca1 --- /dev/null +++ b/2019/AoC.playground/contents.xcplayground @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2019/AoC.playground/playground.xcworkspace/contents.xcworkspacedata b/2019/AoC.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/2019/AoC.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2019/AoC.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/2019/AoC.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/2019/AoC.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + +