From 020ec8c5444f547893de69ee0073e151a9764caf Mon Sep 17 00:00:00 2001 From: David Vidmar Date: Wed, 13 Dec 2023 19:53:48 +0100 Subject: [PATCH] Day 11 solution part 1 --- Day11/Day11/input-sample.txt | 10 +++ Day11/Day11/input.txt | 140 +++++++++++++++++++++++++++++++++++ Day11/Day11/main.swift | 121 ++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 Day11/Day11/input-sample.txt create mode 100644 Day11/Day11/input.txt create mode 100644 Day11/Day11/main.swift diff --git a/Day11/Day11/input-sample.txt b/Day11/Day11/input-sample.txt new file mode 100644 index 0000000..986aad4 --- /dev/null +++ b/Day11/Day11/input-sample.txt @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... diff --git a/Day11/Day11/input.txt b/Day11/Day11/input.txt new file mode 100644 index 0000000..bf6403e --- /dev/null +++ b/Day11/Day11/input.txt @@ -0,0 +1,140 @@ +........#..........................#...............#.....#..................................#..........................#.................... +..............................................................................#.........................................................#... +............#..............................#....................#.........................................#................................. +................................#........................................................................................................... +....................................................................................................#........................#.............. +..................#.....#.............................#..............................................................#...................... +.....................................#..............................#......#....................#.......#................................... +...................................................................................#................................................#....... +.......#.....................#..................................#.............................................#............................. +..........................................................#............................#.................................................... +#............................................#.....#.......................................................................#................ +..................................#...........................................#.................................................#.........#. +........................#........................................................................#.......................................... +....#.........#..........................................................................#..........................#....................... +..............................#...........#......................#.......................................................................... +..................#.................#....................................................................................................... +...........#................................................................................................................................ +......................................................#...................#...................#...................................#........# +............................#...............#............................................................................................... +....#................................................................................................#...............#........#............. +.....................................#...........#...........#...............#..........#..............................................#.... +..............#......................................................#......................................#............#.................. +.........#.....................................................................................#............................................ +........................................................................................................#................................... +............................................................................................................................................ +...#...........................................#..........................#................................................................. +.................................................................................................#.......................................... +.............................#........................................................#....................#........#...........#........... +............#......#.....................#.........#................#....................................................................... +......................................................................................................#..................................#.. +..............................................................#............................................................................. +.#........................#..............................................................#.................................................. +.........#.........................................................................#...............#...............#...............#........ +..................................#......................................#.................................................................. +............................................#............#.......#.............................#............................................ +............................#.......................#..........................................................#.......#.......#..........#. +.....#..................................................................................#................................................... +.................#.....................................................#..............................#..................................... +.........................................#.....#............#......................................................................#........ +..........................................................................................................#................................. +.................................................................#.............#............................................................ +.......................#.....#......................#......................................................................#................ +.#...........#.........................#.....................................................#.........#.........................#.......... +..................................................................................#..............................#.......................... +.......#...................................................................#................................................................ +................#..............#......................................................#...........#.....................#.............#..... +.........................#...................#.............................................................#...............................# +............................................................................................................................................ +........................................#.....................................................................................#............. +....................#...............................................#........#........................#..................................... +......#....................#................................#...............................#.....................#......................... +.#.......................................................................................................................................... +............................................................................................................................................ +................#.............#...........#..........#............#....................................................#........#.....#..... +.....................................#...................................................#........#...........#............................. +....................#.........................................#............#................................................................ +#.................................................#..................................#.....................................#................ +............................................#................................................#.....................#........................ +..................................#.................................................................................................#....... +.........#...............#..............#........................#............#..............................#.............................. +..............................#.........................#.......................................#.....#..................................... +...............................................#.......................#.................................................................... +.....................#...................................................................................................................... +...............#...........................................................................................#................................ +..#...................................#....................................#........................#............#.............#............ +............................................#............................................#.............................................#.... +...............................................................#............................................................................ +........#.......................................................................................#..........................#................ +..........................#.......#......................#....................#............................................................. +....#...........#.....................................................................................................#..................... +...................................................................#..............#...................#..........................#.......... +..............................#..................................................................................#.......................... +.............#......#........................................#.........#..........................#......................................... +.................................................#...................................#......................#............................#.. +........#..............................................#.................................................................................... +......................................#...................................#...................................................#............. +............................................................................................................................................ +........................#.......................................................#.......................#................................... +........................................................................................................................#.........#......... +.......#.................................................................................................................................... +.............................................................#.....#........................#......................#.......................# +#...........#.........................................................................#..................................................... +...................................................#............................................#..........................#.........#...... +...................#................#....................................................................#.....#............................ +............................................................................................................................................ +..........................#............................#.......#.............................#.............................................. +....#...................................#........#......................#.....#............................................................. +.....................................................................................................#.................#.................... +............................................#................................................................#.....................#........ +.........#.......................................................#...................#...................................................... +............................................................................................................................................ +................................#........................#.................#................................................................ +..........................#.........................................#.......................................................#..............# +.#.................................................#.........#.............................................................................. +..................#.................#.............................................#.........#...........#............#...................... +.......................................................................................................................................#.... +.........#..................#............................................................................................................... +............................................#........................................#.............................................#........ +........................................................................#................................................................... +.#.................................................#..............#...........#............................#................................ +....................#.................#.........................................................#.........................................#. +.............#.............................................................................#......................#........#................ +...............................#......................................................................#..........................#.......... +............................................................................................................................................ +........................#................................................#..............#................................................... +........#.........................#......#.........#.........#.............................................................................. +..................................................................#................#............................#........................... +..............................................................................................#.....#....................................... +.....#......................................................................#............................................................... +...................#.........................#........................................#..............................#..................#... +.#.........................#.............................#.......................................#................................#......... +............................................................................................................................................ +................................................#........................#...................................................#.............. +...........#............#.............................................................................#..................................... +..................................#................................#...........#....................................#....................... +#.........................................#....................................................#...............#............................ +.............................#...........................................................................................................#.. +.....#.......#.................................#.......................................#...........................................#........ +........................................................................................................#...................#............... +...................................#.........................#.............................................................................. +.........#...........................................................#.............#..............................#......................... +..................#........#.......................#....................................................................#......#........#... +........................................................................................#...........#....................................... +.................................#.......#..................................................................#............................... +.............#......................................................................................................................#....... +#.............................................................................#..................#.......................................... +....................#................#.......................#.............................#............#................................... +....................................................................#...........................................#..........#.....#.......... +...............................#.......................#...............................................................................#.... +........#.......#...........................................................................................#............................... +........................#..................................................................................................................# +............................................................................................................................................ +..............................................................................................#......................................#...... +..........................................#..............................#...........#............................#......................... +............#.............#..................................#..........................................#.................#................. +........................................................................................................................................#... +...................#.......................................................................#................................................ +#.................................#..................#.......................#.............................................................. +.............................#......................................................................#.....#.....#...................#....... +......#........#.................................#............#......#...................................................................... diff --git a/Day11/Day11/main.swift b/Day11/Day11/main.swift new file mode 100644 index 0000000..290755d --- /dev/null +++ b/Day11/Day11/main.swift @@ -0,0 +1,121 @@ +import Foundation + +let day = "11" +print("AoC 2023, Day \(day)\n") + +let path = "/Users/david/Library/CloudStorage/OneDrive-Personal/20-29 Projects/21 Code/21.24 AdventOfCode/AdventOfCode2023-Swift/" +let content = try String(contentsOfFile: path + "/Day\(day)/Day\(day)/input.txt", encoding: String.Encoding.utf8) +let lines = content.components(separatedBy: "\n").filter { !$0.isEmpty } + +// parse + +var points: [(Int, Int)] = [] +for (l, line) in lines.enumerated() { + for (c, char) in line.enumerated() { + if char == "#" { points.append((l, c)) } + } +} +//print(points) + +// expand COLUMNS +for c in (0.. c { points[i].1 = p.1 + 1 } + } +// print(points) + } +} + +// expand ROWS +for r in (0.. r { points[i].0 = p.0 + 1 } + } +// print(points) + } +} + +// parse + +//var map: [[Int]] = [] +//var i = 0 +//for line in lines { +// map.append(line.map( { $0 == "." ? 0 : 1 })) +//} + +//printMap(map: map) +//print() + +// expand rows + +//for i in (0.. \(j): \(r) = \( abs(p.0 - r.0) + abs(p.1 - r.1) )") + result1 += abs(p.0 - r.0) + abs(p.1 - r.1) + } + } +} + +print("Part 1: \(result1)") + +// part 2 + +var result2 = lines.count +//... + +print("Part 2: \(result2)") + +func printMap(map: [[Int]]) { + for row in map { + print(row) + } +}