My solutions for Advent of Code 2017.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Day 01 - Inverse Captcha
Day 02 - Corruption Checksum
Day 03 - Spiral Memory
Day 04 - High-Entropy Passphrases
Day 05 - A Maze of Twisty Trampolines, All Alike
Day 06 - Memory Reallocation
Day 07 - Recursive Circus
Day 08 - I Heard You Like Registers
Day 09 - Stream Processing
Day 10 - Knot Hash
Day 11 - Hex Ed
Day 12 - Digital Plumber
Day 13 - Packet Scanners
Day 14 - Disk Defragmentation
Day 15 - Dueling Generators
Day 16 - Permutation Promenade
Day 17 - Spinlock
Day 18 - Duet
Day 19 - A Series of Tubes
Day 20 - Particle Swarm
Day 21 - Fractal Art
Day 22 - Sporifica Virus
Day 23 - Coprocessor Conflagration
Day 24 - Electromagnetic Moat
Day 25 - The Halting Problem
.gitignore
README.md

README.md

Advent of Code 2017

This directory contains my solutions to the 25-day Advent of Code 2017. I'll be trying to solve as many as I can in Swift 4, but if I run into trouble I may switch to some other language. My plan is for each day to have its own subdirectory, containing these files:

  • part1-problem.md, part2-problem.md. Descriptions of the day's two puzzles (Part 1 and Part 2), copied from the AoC website. The way it works is, Part 2 is a twist on Part 1 that is disclosed after you've entered the correct answer to Part 1.
  • main.swift. My solution logic, in the form of a solve1() function for Part 1 and a solve2() function for Part 2. If the code gets big and unwieldy I'll split it across additional .swift files. The main logic, though, must be in main.swift, and I expect to always use functions called solve1() and solve2().
  • input.swift. The input data, in the form of a global string array variable called inputLines. The same input data is used for both Part 1 and Part 2. Different AoC users get different input data, so if you explore other people's AoC repositories their input will likely not match mine.
  • answers.swift. String variables containing the correct answers for Part 1 and Part 2, assuming I'm able to find them out by solving the day's puzzles. I figure at some point I might want to set up some kind of automated regression testing.
  • README.md (optional). I'm thinking this could be a place for general discussion of obstacles I encountered and things I learned. I may or may not get around to creating this file for any given day.

My AoC code usually starts quick and dirty. In particular, I'll often start Part 2 by copy-pasting the solve1() code into solve2(). To varying degrees I will come back and clean the code up, but my priority will be whatever it takes to get the correct answer as fast as I can.

I've been using CodeRunner to code, run, and debug these programs. [Update: I've switched to Xcode for Swift coding. More about this in my Day 3 notes.] If you don't have CodeRunner you can run them from the command line, after cd-ing to that day's directory:

# Swift
swiftc -o main *.swift && ./main
# Python
python MyFile.py
# Objective-C
xcrun clang -fobjc-arc -framework Foundation -ObjC -o MyFile.out MyFile.m
MyFile.out

TODO: Add instructions for running Java from the command line. Add instructions for using homebrew to install Java (my preference).

TODO: Figure out how to invoke the debugger from the command line, and add instructions here.

Links on the AoC website look like this:

Tips

TODO: Add notes on AoC in general, how it works, more tips.

  • Beware accidental add trailing newlines in the input.txt files.
    • In Python, can strip trailing newlines before splitting the file into lines:
       return [line.rstrip('\n') for line in open(filePath)]
    • In Swift, can use where as a loop condition:
       for line in lines where !line.isEmpty {