From 5a21949425d5cb9b626b63a200cb1319afb4e957 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 25 Dec 2015 10:21:53 +0000 Subject: [PATCH] Day 25 --- SIGNED.md | 29 +++--- advent-of-code-25.html | 166 ++++++++++++++++++++++++++++++++ advent25.ipynb | 212 +++++++++++++++++++++++++++++++++++++++++ advent25.txt | 1 + 4 files changed, 395 insertions(+), 13 deletions(-) create mode 100644 advent-of-code-25.html create mode 100644 advent25.ipynb create mode 100644 advent25.txt diff --git a/SIGNED.md b/SIGNED.md index 5aea4d3..2ec1423 100644 --- a/SIGNED.md +++ b/SIGNED.md @@ -3,19 +3,19 @@ -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 -iQIcBAABCAAGBQJWe91LAAoJEJPB2e07PgbqODAQAJ/H9uBDWYgfUkGdnL2i4hqg -tUCjNZAsw+VaHN4RFr0x9CGTmI2lf7MRrEy+/FwLamJIx3LVmrWrEG5xouzkIO7p -0Dq1M3xZgJBEzh+PW2J+X3HllLMTe/y9QnzrJFGff9/xzlGRxZ7DKwyvzHhAMl5u -00AJoWAwQkxlvKOXZiES6ROocXLx1GonrG5j76SC6B2tf4NQVlvymR8ivID4dIms -R3khvYShuO24naJaKyjdnR4aTJCfE1zEJ+uPJNsf4GIf1RGRlyU9b+vSmcsblJnO -vmpY5X76KhiYsV9FOfMkUq19q6kooEmswNIiUcXhzWm+BRMgtCfWk/8U64Dxfixc -CS8QSaOGuJAxQl4VPZU9Z5t8piQDbnQlGxiJ+8t+PgRqDWS9A03UlITKMum8njyw -dsq9z/eNFQ8+kSVb9PegnhT6bwCCSxQFOZp65aWekXPe1nwCydvyvyV38/4eyHwq -a8z/DJsco5AFJT+pDn3Qe4WH/jspI23gx25BtNysM2l9Np0x/WK+ALC/n/AFRq6A -c7XE2Oo8+OSU8g4TH5cbmVYxg11dsS5UlERtxMA6R01riYKIHxIcnyPzxXUlyuhw -GN7k/GeR3OHpNhauD4HOfinSE+UJ9qVhwUTDtLlMs0f+fnA+T5ey+EI/dDr3BM1L -a9ETHzNPBsZfcFqmAm8D -=0oJU +iQIcBAABCAAGBQJWfRjHAAoJEJPB2e07PgbqWh4QAIGsjkyCirCOXHdHX09+T7ic +GdAy2YUozniZ2pUdc63S0z+luM2XOCl2ctu6VnVWfg8OP57T3YEqGDQ8Rgifcipu +AJxtpEyDe1cf1L1nq8B4QMBhP1vkbW0OCdcmhI3j0nbZ/HwQHyEeSAQyyF2RFp6B +NEdJ5pivQtifahzFSBYFv/49rnZpjdRR0WJTMmdK5bsaj6DgXpy5ucodscX4tf3X +bDs47NKmqf8rDJjqfDeNUmsRvzjCMFGu5/NIOJJO/jqhABiwbGngEfLEQ3ZQneMl +WaBa3Ve46Tq4ZFWpkGJCMN0WoDeuyESJklilpSDgdQj5kxr5fs/ywT3mKsSwobqk +RIgpL6xzv1XpL8UXwR5aJcVb1onAZcZv97qIYXPZb5b608DGgxkocugYS06LNxPT +HGQXR6/W68yD7HbY8B9/dlqdL3+KL1kuBEGaZ44F9+ELvi/vlPoeRLJ296gdZYJf +I/zNGxA9avWGmvPzM3XYAMkIjWIKCAG8G7drlVhLt6O7CWSMxr7GtFk2Ja1ysLLy +2c5hnWwJqyU+tA3Xoz4/fq25YlNv0zNjGogvm8uhNFP3nPxmJ+tQaUDSS+0ydV31 +4b3z047K+v2ajsp0aoG2Huzrb1MlXZzlMj2rUub3z0xpz13T4TunyxUS8NQB1LU8 +a2qNQVQheMbFYtLP/VQK +=MEXU -----END PGP SIGNATURE----- ``` @@ -58,6 +58,7 @@ size exec file contents 10190 advent-of-code-22.html cb57ad829bd31e59807f3f0ecc95c603eb85b2d9f9e5cbf9432e80283b689298 6910 advent-of-code-23.html fff58431db66635a7dc9b537f3d0d87a10ac9b20acd6fcb9cf5f8c99e6f40f39 8408 advent-of-code-24.html 05fd8b977adf711d5911768855e79f875eb767e47dfc0656882fb49d2b3d8960 +8442 advent-of-code-25.html 4e4155c4f58985e9bb31034a0c75ab4deb68fbb2364669e535ddda7b8dc97534 109395 advent-of-code.ipynb 7292eeb9a8019f6931037c70105ab96bf691074dbe963736b6429cb4d4373f51 25607 advent01.ipynb c33ad39a77803a6870dd74998da98e3bb9c2c2db37c34167b330a01d663717e7 7001 advent01.txt 79312922877bdedd09ce0886a42b3d7f7ed092e2218579fb7d6ac1cb38cedebe @@ -103,6 +104,8 @@ size exec file contents 298 advent23.txt 780557c20cbab27946114d4cf04359045dd76b6bfdb28b5bde2e1ceb2c520173 78473 advent24.ipynb 3c6e8498ce5b987ee45708979dbcfb77a255d6064a150e9a8650ed903c67f324 86 advent24.txt 341dd3c96143cb589467239c9a9812c6f62406c33a359247049613641b890ff6 +4396 advent25.ipynb 5fcb7ff9bfe200971216d337a72a173219f3762bfec2e7c2469159b66a962217 +99 advent25.txt 2da41ec837841ce65a6dafc74bffe9f914217d74c0e64fcdf12e3f01049557d7 ``` #### Ignore diff --git a/advent-of-code-25.html b/advent-of-code-25.html new file mode 100644 index 0000000..b5ac55b --- /dev/null +++ b/advent-of-code-25.html @@ -0,0 +1,166 @@ + + + + +Day 25 - Advent of Code + + + + + + +

Advent of Code

Neil Smith 50*
+ + + +
+

--- Day 25: Let It Snow ---

Merry Christmas! Santa is booting up his weather machine; looks like you might get a white Christmas after all.

+

The weather machine beeps! On the console of the machine is a copy protection message asking you to enter a code from the instruction manual. Apparently, it refuses to run unless you give it that code. No problem; you'll just look up the code in the--

+

"Ho ho ho", Santa ponders aloud. "I can't seem to find the manual."

+

You look up the support number for the manufacturer and give them a call. Good thing, too - that 49th star wasn't going to earn itself.

+

"Oh, that machine is quite old!", they tell you. "That model went out of support six minutes ago, and we just finished shredding all of the manuals. I bet we can find you the code generation algorithm, though."

+

After putting you on hold for twenty minutes (your call is very important to them, it reminded you repeatedly), they finally find an engineer that remembers how the code system works.

+

The codes are printed on an infinite sheet of paper, starting in the top-left corner. The codes are filled in by diagonals: starting with the first row with an empty first box, the codes are filled in diagonally up and to the right. This process repeats until the infinite paper is covered. So, the first few codes are filled in in this order:

+
   | 1   2   3   4   5   6  
+---+---+---+---+---+---+---+
+ 1 |  1   3   6  10  15  21
+ 2 |  2   5   9  14  20
+ 3 |  4   8  13  19
+ 4 |  7  12  18
+ 5 | 11  17
+ 6 | 16
+
+

For example, the 12th code would be written to row 4, column 2; the 15th code would be written to row 1, column 5.

+

The voice on the other end of the phone continues with how the codes are actually generated. The first code is 20151125. After that, each code is generated by taking the previous one, multiplying it by 252533, and then keeping the remainder from dividing that value by 33554393.

+

So, to find the second code (which ends up in row 2, column 1), start with the previous value, 20151125. Multiply it by 252533 to get 5088824049625. Then, divide that by 33554393, which leaves a remainder of 31916031. That remainder is the second code.

+

"Oh!", says the voice. "It looks like we missed a scrap from one of the manuals. Let me read it to you." You write down his numbers:

+
   |    1         2         3         4         5         6
+---+---------+---------+---------+---------+---------+---------+
+ 1 | 20151125  18749137  17289845  30943339  10071777  33511524
+ 2 | 31916031  21629792  16929656   7726640  15514188   4041754
+ 3 | 16080970   8057251   1601130   7981243  11661866  16474243
+ 4 | 24592653  32451966  21345942   9380097  10600672  31527494
+ 5 |    77061  17552253  28094349   6899651   9250759  31663883
+ 6 | 33071741   6796745  25397450  24659492   1534922  27995004
+
+

"Now remember", the voice continues, "that's not even all of the first few numbers; for example, you're missing the one at 7,1 that would come before 6,2. But, it should be enough to let your-- oh, it's time for lunch! Bye!" The call disconnects.

+

Santa looks nervous. Your puzzle input contains the message on the machine's console. What code do you give the machine?

+
+

Your puzzle answer was 9132360.

--- Part Two ---

The machine springs to life, then falls silent again. It beeps. "Insufficient fuel", the console reads. "Fifty stars are required before proceeding. One star is available."

+

..."one star is available"? You check the fuel tank; sure enough, a lone star sits at the bottom, awaiting its friends. Looks like you need to provide 49 yourself.

+
+

+If you like, you can . +

+

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, all that is left is for you to admire your advent calendar.

+

If you still want to see it, you can get your puzzle input.

+

You can also + this puzzle.

+
+ + + + + + diff --git a/advent25.ipynb b/advent25.ipynb new file mode 100644 index 0000000..c6c1136 --- /dev/null +++ b/advent25.ipynb @@ -0,0 +1,212 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import itertools" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def coordinates():\n", + " row = 1\n", + " col = 1\n", + " while True:\n", + " yield row, col\n", + " if row == 1:\n", + " row = col + 1\n", + " col = 1\n", + " else:\n", + " row -= 1\n", + " col += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 1),\n", + " (2, 1),\n", + " (1, 2),\n", + " (3, 1),\n", + " (2, 2),\n", + " (1, 3),\n", + " (4, 1),\n", + " (3, 2),\n", + " (2, 3),\n", + " (1, 4),\n", + " (5, 1),\n", + " (4, 2),\n", + " (3, 3),\n", + " (2, 4),\n", + " (1, 5),\n", + " (6, 1),\n", + " (5, 2),\n", + " (4, 3),\n", + " (3, 4),\n", + " (2, 5)]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(itertools.islice(coordinates(), 20))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def code():\n", + " c = 20151125\n", + " while True:\n", + " yield c\n", + " c = (c * 252533) % 33554393" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{(1, 1): 20151125,\n", + " (1, 2): 18749137,\n", + " (1, 3): 17289845,\n", + " (1, 4): 30943339,\n", + " (1, 5): 10071777,\n", + " (2, 1): 31916031,\n", + " (2, 2): 21629792,\n", + " (2, 3): 16929656,\n", + " (2, 4): 7726640,\n", + " (2, 5): 15514188,\n", + " (3, 1): 16080970,\n", + " (3, 2): 8057251,\n", + " (3, 3): 1601130,\n", + " (3, 4): 7981243,\n", + " (4, 1): 24592653,\n", + " (4, 2): 32451966,\n", + " (4, 3): 21345942,\n", + " (5, 1): 77061,\n", + " (5, 2): 17552253,\n", + " (6, 1): 33071741}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{k: v for k, v in zip(itertools.islice(coordinates(), 20), code())}" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[(4, 4)]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(itertools.islice(itertools.dropwhile(lambda c: not (c[0] == 4 and c[1] == 4), coordinates()), 1))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{(2981, 3075): 9132360}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# To continue, please consult the code grid in the manual. Enter the code at row 2981, column 3075.\n", + "target_row = 2981\n", + "target_col = 3075\n", + "{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", + " zip(coordinates(), code())),\n", + " 1)}" + ] + }, + { + "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 +} diff --git a/advent25.txt b/advent25.txt new file mode 100644 index 0000000..e050407 --- /dev/null +++ b/advent25.txt @@ -0,0 +1 @@ +To continue, please consult the code grid in the manual. Enter the code at row 2981, column 3075. -- 2.34.1