Started work on 2024/08 P1
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
## \-\-- Day 10: Elves Look, Elves Say \-\--
|
||||
|
||||
Today, the Elves are playing a game called
|
||||
[look-and-say](https://en.wikipedia.org/wiki/Look-and-say_sequence).
|
||||
They take turns making sequences by reading aloud the previous sequence
|
||||
and using that reading as the next sequence. For example, `211` is read
|
||||
as \"one two, two ones\", which becomes `1221` (`1` `2`, `2` `1`s).
|
||||
|
||||
Look-and-say sequences are generated iteratively, using the previous
|
||||
value as input for the next step. For each step, take the previous
|
||||
value, and replace each run of digits (like `111`) with the number of
|
||||
digits (`3`) followed by the digit itself (`1`).
|
||||
|
||||
For example:
|
||||
|
||||
- `1` becomes `11` (`1` copy of digit `1`).
|
||||
- `11` becomes `21` (`2` copies of digit `1`).
|
||||
- `21` becomes `1211` (one `2` followed by one `1`).
|
||||
- `1211` becomes `111221` (one `1`, one `2`, and two `1`s).
|
||||
- `111221` becomes `312211` (three `1`s, two `2`s, and one `1`).
|
||||
|
||||
Starting with the digits in your puzzle input, apply this process 40
|
||||
times. What is *the length of the result*?
|
||||
|
||||
Your puzzle answer was `360154`.
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
Neat, right? You might also enjoy hearing [John Conway talking about
|
||||
this sequence](https://www.youtube.com/watch?v=ea7lJkEhytA) (that\'s
|
||||
Conway of *Conway\'s Game of Life* fame).
|
||||
|
||||
Now, starting again with the digits in your puzzle input, apply this
|
||||
process *50* times. What is *the length of the new result*?
|
||||
|
||||
Your puzzle answer was `5103798`.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars:
|
||||
\*\*
|
||||
|
||||
At this point, you should [return to your Advent calendar](/2015) and
|
||||
try another puzzle.
|
||||
|
||||
Your puzzle input was `1113122113`{.puzzle-input}.
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/bin/python3
|
||||
import sys,time,re
|
||||
from pprint import pprint
|
||||
from itertools import groupby
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int,get_re,nprint,lprint,loadFile
|
||||
start_time = time.time()
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
part = 1
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
if part == 1:
|
||||
instructions = loadFile(input_f)[0]
|
||||
print(instructions)
|
||||
|
||||
for i in range(0,50):
|
||||
numbers = [(len(list(group)),key) for key, group in groupby(instructions)]
|
||||
result = ''
|
||||
for n in numbers:
|
||||
result += str(n[0])+str(n[1])
|
||||
#print(instructions,'->',result)
|
||||
instructions = result
|
||||
#input()
|
||||
print(len(instructions))
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
if part == 2:
|
||||
exit()
|
||||
|
||||
print("--- %s seconds ---" % (time.time() - start_time))
|
||||
Reference in New Issue
Block a user