Fixed typo
[advent-of-code-15.git] / advent03.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {
7 "collapsed": true
8 },
9 "outputs": [],
10 "source": [
11 "pi3 = open('advent03.txt').read().strip()"
12 ]
13 },
14 {
15 "cell_type": "code",
16 "execution_count": 2,
17 "metadata": {
18 "collapsed": false
19 },
20 "outputs": [
21 {
22 "data": {
23 "text/plain": [
24 "2081"
25 ]
26 },
27 "execution_count": 2,
28 "metadata": {},
29 "output_type": "execute_result"
30 }
31 ],
32 "source": [
33 "import collections\n",
34 "\n",
35 "x, y = 0, 0\n",
36 "houses = collections.defaultdict(int)\n",
37 "houses[(0,0)] = 1\n",
38 "\n",
39 "for direction in pi3:\n",
40 " if direction == \"^\":\n",
41 " x += 1\n",
42 " if direction == 'v':\n",
43 " x -= 1\n",
44 " if direction == '>':\n",
45 " y += 1\n",
46 " if direction == '<':\n",
47 " y -= 1\n",
48 " houses[(x, y)] += 1\n",
49 "len(houses)"
50 ]
51 },
52 {
53 "cell_type": "code",
54 "execution_count": 3,
55 "metadata": {
56 "collapsed": false
57 },
58 "outputs": [
59 {
60 "data": {
61 "text/plain": [
62 "2341"
63 ]
64 },
65 "execution_count": 3,
66 "metadata": {},
67 "output_type": "execute_result"
68 }
69 ],
70 "source": [
71 "import collections\n",
72 "\n",
73 "x, y, rx, ry = 0, 0, 0, 0\n",
74 "houses = collections.defaultdict(int)\n",
75 "houses[(0,0)] = 2\n",
76 "\n",
77 "for i in range(0, len(pi3), 2):\n",
78 " direction = pi3[i]\n",
79 " rdirection = pi3[i+1]\n",
80 " if direction == \"^\":\n",
81 " x += 1\n",
82 " if direction == 'v':\n",
83 " x -= 1\n",
84 " if direction == '>':\n",
85 " y += 1\n",
86 " if direction == '<':\n",
87 " y -= 1\n",
88 " houses[(x, y)] += 1\n",
89 " if rdirection == \"^\":\n",
90 " rx += 1\n",
91 " if rdirection == 'v':\n",
92 " rx -= 1\n",
93 " if rdirection == '>':\n",
94 " ry += 1\n",
95 " if rdirection == '<':\n",
96 " ry -= 1\n",
97 " houses[(rx, ry)] += 1\n",
98 "len(houses)"
99 ]
100 },
101 {
102 "cell_type": "code",
103 "execution_count": null,
104 "metadata": {
105 "collapsed": true
106 },
107 "outputs": [],
108 "source": []
109 }
110 ],
111 "metadata": {
112 "kernelspec": {
113 "display_name": "Python 3",
114 "language": "python",
115 "name": "python3"
116 },
117 "language_info": {
118 "codemirror_mode": {
119 "name": "ipython",
120 "version": 3
121 },
122 "file_extension": ".py",
123 "mimetype": "text/x-python",
124 "name": "python",
125 "nbconvert_exporter": "python",
126 "pygments_lexer": "ipython3",
127 "version": "3.4.3"
128 }
129 },
130 "nbformat": 4,
131 "nbformat_minor": 0
132 }