{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[Advent Of Code](http://adventofcode.com/) [2016](http://adventofcode.com/2016/) [Day 1 Part 1: No Time for a Taxicab](http://adventofcode.com/2016/day/1)\n", "\n", "- Cell #1 has decent, straightforward, readable code.\n", "- Cell #2 uses vector math with numpy to be more readable.\n", "- Cell #5 is more readable yet,\n", "but requires understanding of complex numbers.\n", "- Cell #9 uses namedtuples.\n", "- Cell #10 uses a class based on namedtuples.\n", "- Cell #11 uses a classes based on complex numbers.\n", "- Cells #6 through #8 explore functional approaches,\n", "descending into obfuscation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Definitions:\n", "\n", "- [course](https://en.wikipedia.org/wiki/Course_(navigation%29): the direction one is going\n", "- deflection: how much one turns right or left" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'''First, a very straightforward readable solution.\n", "Coordinates are in tuples.'''\n", " \n", "from math import sin, cos, radians\n", "\n", "deflection = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", "}\n", "\n", "NORTH = 0\n", "\n", "def manhattan_distance(*points):\n", " return sum(\n", " abs(coordinate1 - coordinate2)\n", " for coordinate1, coordinate2 in zip(*points))\n", "\n", "def follow_route(\n", " moves=None, # iterable of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=(0., 0.), # (east, north) Unit is 1 block for each coordinate.\n", "):\n", " course = starting_course\n", " location = starting_location\n", " for turn_code, *distance_chars in moves:\n", " course += deflection[turn_code]\n", " distance = float(''.join(distance_chars))\n", " location = tuple(\n", " coordinate + distance * func(radians(course))\n", " for coordinate, func in zip(location, (sin, cos)))\n", "\n", " return location\n", " \n", "def process_route(raw_instructions):\n", " instructions = (s.strip() for s in raw_instructions.split(','))\n", " starting_location = (0, 0)\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " distance = round(manhattan_distance(destination, starting_location))\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=distance))\n", " \n", "def main():\n", " raw_routes = (\n", " ('20161202-aoc-day1part1-test', 'R5, L5, R5, R3'),\n", " # from https://github.com/hakim89/adventofcode/raw/master/day01/part-01.py\n", " ('20161202-aoc-day1part1-long',\n", " '''\n", " R4, R5, L5, L5, L3, R2, R3, R2, L1, R5, R1, L5, R2, L2, L4, R3,\n", " L1, R4, L5, R4, R3, L5, L3, R4, R2, L5, L5, R2, R3, R5, R4, R2,\n", " R1, L1, L5, L2, L3, L4, L5, L4, L5, L1, R3, R4, R5, R3, L5, L4,\n", " L3, L1, L4, R2, R5, R5, R4, L2, L4, R3, R1, L2, R5, L5, R1, R1,\n", " L1, L5, L5, L2, L1, R5, R2, L4, L1, R4, R3, L3, R1, R5, L1, L4,\n", " R2, L3, R5, R3, R1, L3'''),\n", " )\n", " for filename, raw_instructions in raw_routes:\n", " with open(filename, 'w') as f:\n", " f.write(raw_instructions)\n", " \n", " for filename, _ in raw_routes:\n", " with open(filename) as f:\n", " raw_instructions = f.read()\n", " process_route(raw_instructions)\n", " \n", "if __name__ == '__main__':\n", " main()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12.0 blocks away.\n", "Easter Bunny HQ is 44.0 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'Use vector math with numpy.'\n", " \n", "from math import sin, cos, radians\n", "from numpy import array\n", "\n", "deflection = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", "}\n", "\n", "NORTH = 0\n", "\n", "def manhattan_distance(vector):\n", " return sum(map(abs, vector))\n", "\n", "def follow_route(\n", " moves=None, # iterable of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=array([0., 0.]), # [east, north] Unit is 1 block for each coordinate.\n", "):\n", " course = starting_course\n", " location = starting_location.copy()\n", " for turn_code, *distance_chars in moves:\n", " course += deflection[turn_code]\n", " distance = float(''.join(distance_chars))\n", " v = array([func(radians(course)) for func in (sin, cos)])\n", " location += distance * v\n", "\n", " return location\n", "\n", "def process_route(raw_instructions):\n", " instructions = (s.strip() for s in raw_instructions.split(','))\n", " starting_location=array([0., 0.])\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " distance = round(manhattan_distance(destination - starting_location))\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=distance))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " for filename in route_filenames:\n", " with open(filename) as f:\n", " raw_instructions = f.read()\n", " process_route(raw_instructions)\n", " \n", "if __name__ == '__main__': \n", " main()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import cmath\n", "from math import radians" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(8.660254037844387+4.999999999999999j)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cmath.rect(10., radians(30))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'''Use complex numbers to simplify code.\n", "The location calculation is particularly nice.'''\n", " \n", "from math import radians\n", "import cmath\n", "\n", "deflection = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", "}\n", "\n", "NORTH = 0\n", "\n", "def manhattan_distance(vector):\n", " return sum(map(abs, (vector.real, vector.imag)))\n", "\n", "def follow_route(\n", " moves=None, # iterable of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=0+0j, # north + east j Unit is 1 block.\n", "):\n", " course = starting_course\n", " location = starting_location\n", " for turn_code, *distance_chars in moves:\n", " course += deflection[turn_code]\n", " distance = float(''.join(distance_chars))\n", " location += cmath.rect(distance, radians(course))\n", "\n", " return location\n", "\n", "def process_route(raw_instructions):\n", " instructions = (s.strip() for s in raw_instructions.split(','))\n", " starting_location=0.+0.j\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " distance = round(manhattan_distance(destination - starting_location))\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=distance))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " for filename in route_filenames:\n", " with open(filename) as f:\n", " raw_instructions = f.read()\n", " process_route(raw_instructions)\n", " \n", "if __name__ == '__main__': \n", " main()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'''Use functional approach to obfuscate the code.\n", "Look ma, no for loops.'''\n", " \n", "from math import radians\n", "import cmath\n", "from itertools import accumulate, starmap, chain, islice\n", "\n", "NORTH = 0\n", "\n", "def manhattan_distance(vector):\n", " return sum(map(abs, (vector.real, vector.imag)))\n", "\n", "def deflection(move):\n", " deflection_of_turn = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", " }\n", "\n", " turn_code = move[:1]\n", " return deflection_of_turn[turn_code]\n", "\n", "def distance(move):\n", " distance = move[1:]\n", " return float(distance)\n", "\n", "def follow_route(\n", " moves=None, # sequence of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=0+0j, # north + east j Unit is 1 block.\n", "):\n", " distances = map(distance, moves)\n", " deflections = map(deflection, moves)\n", " courses = islice(accumulate(chain(\n", " [starting_course], deflections)), 1, None)\n", " courses = map(radians, courses)\n", " legs = starmap(cmath.rect, zip(distances, courses))\n", " return starting_location + sum(legs)\n", "\n", "def process_route(raw_instructions):\n", " instructions = tuple(map(\n", " lambda s: s.strip(),\n", " raw_instructions.split(',')))\n", " starting_location=0+0j\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " distance = round(manhattan_distance(destination - starting_location))\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=distance))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " list(map(\n", " process_route,\n", " map(lambda f: f.read(), map(open, route_filenames))))\n", " \n", "if __name__ == '__main__': \n", " main()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'''Continue functional approach to obfuscate the code.\n", "This time with no temporary variables in follow_route().'''\n", " \n", "from math import radians\n", "import cmath\n", "from itertools import accumulate, starmap, chain, islice\n", "\n", "NORTH = 0\n", "\n", "def manhattan_distance(vector):\n", " return sum(map(abs, (vector.real, vector.imag)))\n", "\n", "def deflection(move):\n", " deflection_of_turn = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", " }\n", "\n", " turn_code = move[:1]\n", " return deflection_of_turn[turn_code]\n", "\n", "def distance(move):\n", " distance = move[1:]\n", " return float(distance)\n", "\n", "def follow_route(\n", " moves=None, # sequence of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=0+0j, # north + east j Unit is 1 block.\n", "):\n", " return starting_location + sum(\n", " starmap(\n", " cmath.rect,\n", " zip(\n", " map(distance, moves),\n", " map(radians, islice(\n", " accumulate(chain(\n", " [starting_course], map(deflection, moves))),\n", " 1,\n", " None)))))\n", "\n", "def process_route(raw_instructions):\n", " instructions = tuple(map(\n", " lambda s: s.strip(),\n", " raw_instructions.split(',')))\n", " starting_location=0+0j\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " distance = round(manhattan_distance(destination - starting_location))\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=distance))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " list(map(\n", " process_route,\n", " map(lambda f: f.read(), map(open, route_filenames))))\n", " \n", "if __name__ == '__main__': \n", " main()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'Use lambdas for more obfuscation.'\n", " \n", "from math import radians\n", "import cmath\n", "from itertools import accumulate, starmap, chain, islice\n", "\n", "NORTH = 0\n", "\n", "def manhattan_distance(vector):\n", " return sum(map(abs, (vector.real, vector.imag)))\n", "\n", "deflection = dict(map(\n", " lambda x: (x[0][0], x[1]),\n", " zip(\n", " ('RIGHT', 'LEFT'),\n", " (+90, -90) # Unit of values is one degree clockwise.\n", " )\n", "))\n", "\n", "def follow_route(\n", " moves=None, # sequence of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=0+0j, # north + east j Unit is 1 block.\n", "):\n", " return starting_location + sum(starmap(\n", " cmath.rect,\n", " zip(\n", " map(lambda move: float(''.join(move[1:])), moves),\n", " map(\n", " radians,\n", " islice(\n", " accumulate(chain(\n", " [starting_course],\n", " map(lambda move: deflection[move[:1]], moves)\n", " )),\n", " 1,\n", " None)))))\n", "\n", "def process_route(raw_instructions):\n", " instructions = tuple(map(\n", " lambda s: s.strip(),\n", " raw_instructions.split(',')))\n", " starting_location=0.+0.j\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " distance = round(manhattan_distance(destination - starting_location))\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=distance))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " list(map(\n", " process_route,\n", " map(lambda f: f.read(), map(open, route_filenames))))\n", " \n", "if __name__ == '__main__': \n", " main()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "Back to trying to write clean code. Explores using namedtuple and classes based on namedtuples and complex numbers." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'Use namedtuple.'\n", " \n", "from math import sin, cos, radians\n", "from collections import namedtuple\n", "\n", "deflection = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", "}\n", "\n", "NORTH = 0\n", "\n", "Point = namedtuple('Point', ['East', 'North'])\n", "\n", "def manhattan_distance(*points):\n", " return sum(\n", " abs(coordinate1 - coordinate2)\n", " for coordinate1, coordinate2 in zip(*points))\n", "\n", "def follow_route(\n", " moves=None, # iterable of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=Point(0., 0.), # Unit is 1 block for each coordinate.\n", "):\n", " course = starting_course\n", " location = starting_location\n", " for turn_code, *distance_chars in moves:\n", " course += deflection[turn_code]\n", " distance = float(''.join(distance_chars))\n", " location = Point(*(\n", " coordinate + distance * func(radians(course))\n", " for coordinate, func in zip(location, (sin, cos))))\n", "\n", " return location\n", " \n", "def process_route(raw_instructions):\n", " instructions = (s.strip() for s in raw_instructions.split(','))\n", " starting_location = Point(0., .0)\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " distance = round(manhattan_distance(destination, starting_location))\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=distance))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " for filename in route_filenames:\n", " with open(filename) as f:\n", " raw_instructions = f.read()\n", " process_route(raw_instructions)\n", " \n", "if __name__ == '__main__':\n", " main()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'Use class based on namedtuple.'\n", " \n", "from math import sin, cos, radians\n", "from collections import namedtuple\n", "\n", "deflection = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", "}\n", "\n", "NORTH = 0\n", "\n", "class Point(object):\n", " Point = namedtuple('Point', ['North', 'East'])\n", " \n", " def __init__(self, north, east):\n", " self.point = self.Point(North=north, East=east)\n", "\n", " def __len__(self):\n", " return len(self.point)\n", " \n", " def __getitem__(self, i):\n", " return self.point[i]\n", " \n", " def __str__(self):\n", " return '{p.North}N, {p.East}E'.format(p=self.point)\n", " \n", " def __repr__(self):\n", " return '{p.North} North, {p.East} East'.format(p=self.point)\n", " \n", " def __add__(self, value):\n", " return Point(*(\n", " c1 + c2 for c1, c2 in zip(self.point, value.point)))\n", "\n", " def __sub__(self, value):\n", " return Point(*(\n", " c1 - c2 for c1, c2 in zip(self.point, value.point)))\n", " \n", " def __round__(self, ndigits=0):\n", " return Point(*(\n", " round(coordinate, ndigits=ndigits)\n", " for coordinate in self.point\n", " ))\n", " \n", " def __abs__(self):\n", " 'manhattan distance'\n", " return sum(map(abs, self.point))\n", "\n", "def follow_route(\n", " moves=None, # iterable of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=Point(0.,0.), # Unit is 1 block for each coordinate.\n", "):\n", " course = starting_course\n", " location = starting_location\n", " for turn_code, *distance_chars in moves:\n", " course += deflection[turn_code]\n", " distance = float(''.join(distance_chars))\n", "\n", " location = Point(*(\n", " coordinate + distance * func(radians(course))\n", " for coordinate, func in zip(location, (cos, sin))))\n", "\n", " return location\n", " \n", "def process_route(raw_instructions):\n", " instructions = (s.strip() for s in raw_instructions.split(','))\n", " starting_location = Point(0., .0)\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=round(abs(destination - starting_location))))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " for filename in route_filenames:\n", " with open(filename) as f:\n", " raw_instructions = f.read()\n", " process_route(raw_instructions)\n", " \n", "if __name__ == '__main__':\n", " main()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Easter Bunny HQ is 12 blocks away.\n", "Easter Bunny HQ is 44 blocks away.\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "\n", "'Use classes based on complex numbers.'\n", " \n", "from math import sin, cos, radians\n", "import cmath\n", "\n", "deflection = { # Unit of values is one degree clockwise.\n", " 'R': +90,\n", " 'L': -90,\n", "}\n", "\n", "NORTH = 0\n", "\n", "class Point(object):\n", " def __init__(self, north=None, east=None):\n", " self.point = north + east*1j\n", "\n", " def __str__(self):\n", " return '{p.real}N {p.imag}E'.format(p=self.point)\n", " \n", " def __repr__(self):\n", " return '{p.real} North, {p.imag} East'.format(p=self.point)\n", " \n", " def __mul__(self, value):\n", " p = self.point * value\n", " return Point(p.real, p.imag)\n", " \n", " def __rmul__(self, value):\n", " return self.__mul__(value)\n", "\n", " def __add__(self, value):\n", " p = self.point + value.point\n", " return Point(p.real, p.imag)\n", "\n", " def __sub__(self, value):\n", " p = self.point - value.point\n", " return Point(p.real, p.imag)\n", " \n", " def __round__(self, ndigits=0):\n", " return Point(\n", " round(self.point.real, ndigits=ndigits),\n", " round(self.point.imag, ndigits=ndigits),\n", " )\n", " \n", " def __abs__(self):\n", " 'manhattan distance'\n", " return sum(map(abs, (self.point.real, self.point.imag)))\n", " \n", "class Vector(Point):\n", " def __init__(self, length=1., azimuth=0.):\n", " self.point = cmath.rect(length, azimuth)\n", "\n", "def follow_route(\n", " moves=None, # iterable of [RL] strings\n", " # Unit of distance is 1 block.\n", " starting_course=None, # Unit is 1 degree clockwise. 0 is North.\n", " starting_location=Point(0.,0.), # Unit is 1 block for each coordinate.\n", "):\n", " course = starting_course\n", " location = starting_location\n", " for turn_code, *distance_chars in moves:\n", " course += deflection[turn_code]\n", " distance = float(''.join(distance_chars))\n", " location += distance * Vector(azimuth=radians(course))\n", " # The following works also.\n", " # location += Vector(length=distance, azimuth=radians(course))\n", "\n", " return location\n", " \n", "def process_route(raw_instructions):\n", " instructions = (s.strip() for s in raw_instructions.split(','))\n", " starting_location = Point(0., .0)\n", " destination = follow_route(\n", " moves=instructions,\n", " starting_course=NORTH,\n", " starting_location=starting_location,\n", " )\n", " print('Easter Bunny HQ is {distance} blocks away.'.format(\n", " distance=round(abs(destination - starting_location))))\n", " \n", "def main():\n", " route_filenames = (\n", " '20161202-aoc-day1part1-test',\n", " '20161202-aoc-day1part1-long',\n", " )\n", " for filename in route_filenames:\n", " with open(filename) as f:\n", " raw_instructions = f.read()\n", " process_route(raw_instructions)\n", " \n", "if __name__ == '__main__':\n", " main()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }