|
| 1 | +<?php |
| 2 | + |
| 3 | +ini_set("memory_limit", "-1"); |
| 4 | + |
| 5 | +require __DIR__ . '/../vendor/autoload.php'; |
| 6 | + |
| 7 | +use adventofcode\Year2015\LookAndSay; |
| 8 | + |
| 9 | +/** |
| 10 | + * --- Day 10: Elves Look, Elves Say --- |
| 11 | + * |
| 12 | + * Today, the Elves are playing a game called look-and-say. They take turns making sequences by reading aloud the |
| 13 | + * previous sequence and using that reading as the next sequence. For example, 211 is read as "one two, two ones", |
| 14 | + * which becomes 1221 (1 2, 2 1s). |
| 15 | + * |
| 16 | + * Look-and-say sequences are generated iteratively, using the previous value as input for the next step. For each |
| 17 | + * step, take the previous value, and replace each run of digits (like 111) with the number of digits (3) followed |
| 18 | + * by the digit itself (1). |
| 19 | + * |
| 20 | + * For example: |
| 21 | + * |
| 22 | + * - 1 becomes 11 (1 copy of digit 1). |
| 23 | + * - 11 becomes 21 (2 copies of digit 1). |
| 24 | + * - 21 becomes 1211 (one 2 followed by one 1). |
| 25 | + * - 1211 becomes 111221 (one 1, one 2, and two 1s). |
| 26 | + * - 111221 becomes 312211 (three 1s, two 2s, and one 1). |
| 27 | + * |
| 28 | + * Starting with the digits in your puzzle input, apply this process 40 times. What is the length of the result? |
| 29 | + */ |
| 30 | + |
| 31 | +$lookAndSay = new LookAndSay(); |
| 32 | +$result = $lookAndSay->play('3113322113', 40); |
| 33 | +print("The length of the result after 40 rounds is " . strlen($result) . ".\n"); |
| 34 | + |
| 35 | +/** |
| 36 | + * Neat, right? You might also enjoy hearing John Conway talking about this sequence (that's Conway of Conway's |
| 37 | + * Game of Life fame). |
| 38 | + * |
| 39 | + * Now, starting again with the digits in your puzzle input, apply this process 50 times. What is the length of |
| 40 | + * the new result? |
| 41 | + */ |
| 42 | + |
| 43 | +$lookAndSay = new LookAndSay(); |
| 44 | +$result = $lookAndSay->play('3113322113', 50); |
| 45 | +print("The length of the result after 50 rounds is " . strlen($result) . ".\n"); |
0 commit comments