Advent of Code 2018 - Set up

Original Set up The first (meta) problem with Advent of Code is to figure out how you’re going to organize your code for these challenges. How get the input into a usable format, how to keep things in order and minimize the time it takes, etc. At first, I decided to code my solutions in Swift in an Xcode playground. The organization I landed on for that was to make a blank source file and to declare a public let day1Input: String in there....

December 10, 2018 · 6 min

Advent of Code 2018 - Day 7

Problem 1 My understanding of Day 7’s first problem is this: given a series of instructions like the one below, return a String which is the correct order in which the instructions will be executed. The sample data returns "CABDFE". Step C must be finished before step A can begin. Step C must be finished before step F can begin. Step A must be finished before step B can begin. Step A must be finished before step D can begin....

December 8, 2018 · 9 min

Advent of Code 2018 - Day 6

Problem 1 My understanding of Day 6’s first problem is this: given a list of coordinates like the one below, return an Int which is the size of the largest open area that isn’t infinite (using Manhattan or taxicab distance) around a point. The sample data returns 17. 1, 1 1, 6 8, 3 3, 4 5, 5 8, 9 Method My method for solving this problem looks like this:...

December 7, 2018 · 7 min

Advent of Code 2018 - Day 5

Problem 1 My understanding of Day 5’s first problem is this: given a String like "dabAcCaCBAcCcaDA", return an Int which is the number of characters remaining after being reduced by removing pairs of letters which are adjacent, the same letter, and opposite cases. For example "cC" and "Aa". The sample returns 10. Method My method for solving this problem looks like this: Make an outer while loop that will continue until you make it all the way through the String without finding any pairs that can be removed....

December 6, 2018 · 6 min

Advent of Code 2018 - Day 4

Problem 1 My understanding of Day 4’s first problem is this: given a string like the one below, return an Int that is the minute at which the guard who spent the most total minutes asleep was asleep the most, times that guard’s ID number. The sample data returns 240. Sample data: [1518-11-01 00:00] Guard #10 begins shift [1518-11-01 00:05] falls asleep [1518-11-01 00:25] wakes up [1518-11-01 00:30] falls asleep [1518-11-01 00:55] wakes up [1518-11-01 23:58] Guard #99 begins shift [1518-11-02 00:40] falls asleep [1518-11-02 00:50] wakes up [1518-11-03 00:05] Guard #10 begins shift [1518-11-03 00:24] falls asleep [1518-11-03 00:29] wakes up [1518-11-04 00:02] Guard #99 begins shift [1518-11-04 00:36] falls asleep [1518-11-04 00:46] wakes up [1518-11-05 00:03] Guard #99 begins shift [1518-11-05 00:45] falls asleep [1518-11-05 00:55] wakes up Method My method for solving this problem looks like this:...

December 5, 2018 · 9 min

Advent of Code 2018 - Day 3

Problem 1 My understanding of day 3’s first problem is this: given a string that is a list of fabric claims like "#1 @ 1,3: 4x4\n#2 @ 3,1: 4x4\n#3 @ 5,5: 2x2" on a large grid of fabric (with the coordinates starting at the top left), return an Int which is the number square inches claimed more than once. The sample data returns 4. Method To solve this problem I needed:...

December 4, 2018 · 7 min

Advent of Code 2018 - Day 2

Problem 1 My understanding of the second day’s first problem was this: given a list of IDs like "abcdef bababc abbcde abcccd aabcdd abcdee ababab", return a checksum which is the number of IDs that contain exactly two of the same character times the number of IDs that contain exactly three of the same character. IDs can count towards both numbers. The sample returns 12. Method Break up the input into an array of the individual IDs Write a function that takes a string and a count (int) and returns a bool that is whether that string contains exactly “count” of any letter Filter the array using that function for count 2 Filter the array using that function for count 3 Multiply the counts of the filtered arrays together Implementation Again, I start my function by saying let array = string....

December 3, 2018 · 5 min

Advent of Code 2018 - Day 1

Problem 1 My understanding of day 1’s first problem was this: given a string like "+1, -2, +3, +1" , return the Int it reduces to if you add and subtract all the numbers, starting at 0. The actual input was much longer and the elements were separated by newlines instead of spaces, but I accounted for that in my function. The sample data returns 3 Method Here’s how I broke down the problem:...

December 2, 2018 · 5 min