Fixed typo
[advent-of-code-15.git] / advent25.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {
7 "collapsed": true
8 },
9 "outputs": [],
10 "source": [
11 "import itertools"
12 ]
13 },
14 {
15 "cell_type": "code",
16 "execution_count": 2,
17 "metadata": {
18 "collapsed": true
19 },
20 "outputs": [],
21 "source": [
22 "def coordinates():\n",
23 " row = 1\n",
24 " col = 1\n",
25 " while True:\n",
26 " yield row, col\n",
27 " if row == 1:\n",
28 " row = col + 1\n",
29 " col = 1\n",
30 " else:\n",
31 " row -= 1\n",
32 " col += 1"
33 ]
34 },
35 {
36 "cell_type": "code",
37 "execution_count": 3,
38 "metadata": {
39 "collapsed": false
40 },
41 "outputs": [
42 {
43 "data": {
44 "text/plain": [
45 "[(1, 1),\n",
46 " (2, 1),\n",
47 " (1, 2),\n",
48 " (3, 1),\n",
49 " (2, 2),\n",
50 " (1, 3),\n",
51 " (4, 1),\n",
52 " (3, 2),\n",
53 " (2, 3),\n",
54 " (1, 4),\n",
55 " (5, 1),\n",
56 " (4, 2),\n",
57 " (3, 3),\n",
58 " (2, 4),\n",
59 " (1, 5),\n",
60 " (6, 1),\n",
61 " (5, 2),\n",
62 " (4, 3),\n",
63 " (3, 4),\n",
64 " (2, 5)]"
65 ]
66 },
67 "execution_count": 3,
68 "metadata": {},
69 "output_type": "execute_result"
70 }
71 ],
72 "source": [
73 "list(itertools.islice(coordinates(), 20))"
74 ]
75 },
76 {
77 "cell_type": "code",
78 "execution_count": 4,
79 "metadata": {
80 "collapsed": true
81 },
82 "outputs": [],
83 "source": [
84 "def code():\n",
85 " c = 20151125\n",
86 " while True:\n",
87 " yield c\n",
88 " c = (c * 252533) % 33554393"
89 ]
90 },
91 {
92 "cell_type": "code",
93 "execution_count": 7,
94 "metadata": {
95 "collapsed": false
96 },
97 "outputs": [
98 {
99 "data": {
100 "text/plain": [
101 "{(1, 1): 20151125,\n",
102 " (1, 2): 18749137,\n",
103 " (1, 3): 17289845,\n",
104 " (1, 4): 30943339,\n",
105 " (1, 5): 10071777,\n",
106 " (2, 1): 31916031,\n",
107 " (2, 2): 21629792,\n",
108 " (2, 3): 16929656,\n",
109 " (2, 4): 7726640,\n",
110 " (2, 5): 15514188,\n",
111 " (3, 1): 16080970,\n",
112 " (3, 2): 8057251,\n",
113 " (3, 3): 1601130,\n",
114 " (3, 4): 7981243,\n",
115 " (4, 1): 24592653,\n",
116 " (4, 2): 32451966,\n",
117 " (4, 3): 21345942,\n",
118 " (5, 1): 77061,\n",
119 " (5, 2): 17552253,\n",
120 " (6, 1): 33071741}"
121 ]
122 },
123 "execution_count": 7,
124 "metadata": {},
125 "output_type": "execute_result"
126 }
127 ],
128 "source": [
129 "{k: v for k, v in zip(itertools.islice(coordinates(), 20), code())}"
130 ]
131 },
132 {
133 "cell_type": "code",
134 "execution_count": 11,
135 "metadata": {
136 "collapsed": false
137 },
138 "outputs": [
139 {
140 "data": {
141 "text/plain": [
142 "[(4, 4)]"
143 ]
144 },
145 "execution_count": 11,
146 "metadata": {},
147 "output_type": "execute_result"
148 }
149 ],
150 "source": [
151 "list(itertools.islice(itertools.dropwhile(lambda c: not (c[0] == 4 and c[1] == 4), coordinates()), 1))"
152 ]
153 },
154 {
155 "cell_type": "code",
156 "execution_count": 17,
157 "metadata": {
158 "collapsed": false
159 },
160 "outputs": [
161 {
162 "data": {
163 "text/plain": [
164 "{(2981, 3075): 9132360}"
165 ]
166 },
167 "execution_count": 17,
168 "metadata": {},
169 "output_type": "execute_result"
170 }
171 ],
172 "source": [
173 "# To continue, please consult the code grid in the manual. Enter the code at row 2981, column 3075.\n",
174 "target_row = 2981\n",
175 "target_col = 3075\n",
176 "{k: v for k, v in itertools.islice(itertools.dropwhile(lambda c: not (c[0][0] == target_row and c[0][1] == target_col), \n",
177 " zip(coordinates(), code())),\n",
178 " 1)}"
179 ]
180 },
181 {
182 "cell_type": "code",
183 "execution_count": null,
184 "metadata": {
185 "collapsed": true
186 },
187 "outputs": [],
188 "source": []
189 }
190 ],
191 "metadata": {
192 "kernelspec": {
193 "display_name": "Python 3",
194 "language": "python",
195 "name": "python3"
196 },
197 "language_info": {
198 "codemirror_mode": {
199 "name": "ipython",
200 "version": 3
201 },
202 "file_extension": ".py",
203 "mimetype": "text/x-python",
204 "name": "python",
205 "nbconvert_exporter": "python",
206 "pygments_lexer": "ipython3",
207 "version": "3.4.3"
208 }
209 },
210 "nbformat": 4,
211 "nbformat_minor": 0
212 }