{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "pi3 = open('advent03.txt').read().strip()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "2081" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import collections\n", "\n", "x, y = 0, 0\n", "houses = collections.defaultdict(int)\n", "houses[(0,0)] = 1\n", "\n", "for direction in pi3:\n", " if direction == \"^\":\n", " x += 1\n", " if direction == 'v':\n", " x -= 1\n", " if direction == '>':\n", " y += 1\n", " if direction == '<':\n", " y -= 1\n", " houses[(x, y)] += 1\n", "len(houses)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "2341" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import collections\n", "\n", "x, y, rx, ry = 0, 0, 0, 0\n", "houses = collections.defaultdict(int)\n", "houses[(0,0)] = 2\n", "\n", "for i in range(0, len(pi3), 2):\n", " direction = pi3[i]\n", " rdirection = pi3[i+1]\n", " if direction == \"^\":\n", " x += 1\n", " if direction == 'v':\n", " x -= 1\n", " if direction == '>':\n", " y += 1\n", " if direction == '<':\n", " y -= 1\n", " houses[(x, y)] += 1\n", " if rdirection == \"^\":\n", " rx += 1\n", " if rdirection == 'v':\n", " rx -= 1\n", " if rdirection == '>':\n", " ry += 1\n", " if rdirection == '<':\n", " ry -= 1\n", " houses[(rx, ry)] += 1\n", "len(houses)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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 }