Started work on 2024/08 P1
This commit is contained in:
parent
1bf03abc75
commit
f3f88f47d1
45
2015/10/10.md
Normal file
45
2015/10/10.md
Normal file
@ -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}.
|
||||
|
40
2015/10/solution.py
Normal file
40
2015/10/solution.py
Normal file
@ -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))
|
111
2024/08/8.md
Normal file
111
2024/08/8.md
Normal file
@ -0,0 +1,111 @@
|
||||
## \-\-- Day 8: Resonant Collinearity \-\--
|
||||
|
||||
You find yourselves on the [roof](/2016/day/25) of a top-secret Easter
|
||||
Bunny installation.
|
||||
|
||||
While The Historians do their thing, you take a look at the familiar
|
||||
*huge antenna*. Much to your surprise, it seems to have been
|
||||
reconfigured to emit a signal that makes people 0.1% more likely to buy
|
||||
Easter Bunny brand [Imitation
|
||||
Mediocre]{title="They could have imitated delicious chocolate, but the mediocre chocolate is WAY easier to imitate."}
|
||||
Chocolate as a Christmas gift! Unthinkable!
|
||||
|
||||
Scanning across the city, you find that there are actually many such
|
||||
antennas. Each antenna is tuned to a specific *frequency* indicated by a
|
||||
single lowercase letter, uppercase letter, or digit. You create a map
|
||||
(your puzzle input) of these antennas. For example:
|
||||
|
||||
............
|
||||
........0...
|
||||
.....0......
|
||||
.......0....
|
||||
....0.......
|
||||
......A.....
|
||||
............
|
||||
............
|
||||
........A...
|
||||
.........A..
|
||||
............
|
||||
............
|
||||
|
||||
The signal only applies its nefarious effect at specific *antinodes*
|
||||
based on the resonant frequencies of the antennas. In particular, an
|
||||
antinode occurs at any point that is perfectly in line with two antennas
|
||||
of the same frequency - but only when one of the antennas is twice as
|
||||
far away as the other. This means that for any pair of antennas with the
|
||||
same frequency, there are two antinodes, one on either side of them.
|
||||
|
||||
So, for these two antennas with frequency `a`, they create the two
|
||||
antinodes marked with `#`:
|
||||
|
||||
..........
|
||||
...#......
|
||||
..........
|
||||
....a.....
|
||||
..........
|
||||
.....a....
|
||||
..........
|
||||
......#...
|
||||
..........
|
||||
..........
|
||||
|
||||
Adding a third antenna with the same frequency creates several more
|
||||
antinodes. It would ideally add four antinodes, but two are off the
|
||||
right side of the map, so instead it adds only two:
|
||||
|
||||
..........
|
||||
...#......
|
||||
#.........
|
||||
....a.....
|
||||
........a.
|
||||
.....a....
|
||||
..#.......
|
||||
......#...
|
||||
..........
|
||||
..........
|
||||
|
||||
Antennas with different frequencies don\'t create antinodes; `A` and `a`
|
||||
count as different frequencies. However, antinodes *can* occur at
|
||||
locations that contain antennas. In this diagram, the lone antenna with
|
||||
frequency capital `A` creates no antinodes but has a
|
||||
lowercase-`a`-frequency antinode at its location:
|
||||
|
||||
..........
|
||||
...#......
|
||||
#.........
|
||||
....a.....
|
||||
........a.
|
||||
.....a....
|
||||
..#.......
|
||||
......A...
|
||||
..........
|
||||
..........
|
||||
|
||||
The first example has antennas with two different frequencies, so the
|
||||
antinodes they create look like this, plus an antinode overlapping the
|
||||
topmost `A`-frequency antenna:
|
||||
|
||||
......#....#
|
||||
...#....0...
|
||||
....#0....#.
|
||||
..#....0....
|
||||
....0....#..
|
||||
.#....A.....
|
||||
...#........
|
||||
#......#....
|
||||
........A...
|
||||
.........A..
|
||||
..........#.
|
||||
..........#.
|
||||
|
||||
Because the topmost `A`-frequency antenna overlaps with a `0`-frequency
|
||||
antinode, there are `14` total unique locations that contain an antinode
|
||||
within the bounds of the map.
|
||||
|
||||
Calculate the impact of the signal. *How many unique locations within
|
||||
the bounds of the map contain an antinode?*
|
||||
|
||||
To begin, [get your puzzle input](8/input).
|
||||
|
||||
Answer:
|
||||
|
68
2024/08/solution.py
Normal file
68
2024/08/solution.py
Normal file
@ -0,0 +1,68 @@
|
||||
#!/bin/python3
|
||||
import sys,time,re
|
||||
from pprint import pprint
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int,get_re,nprint,lprint,grid_valid,loadFile,subTuples,addTuples,toGrid,get_value_in_direction
|
||||
start_time = time.time()
|
||||
|
||||
input_f = 'test'
|
||||
|
||||
part = 1
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
def findAntinodes(grid:list,pos:set,current_node:set):
|
||||
print('Found',current_node,'at',pos)
|
||||
antinodes = []
|
||||
for row in range(pos[0],len(grid)):
|
||||
for col in range(0,len(grid[1])):
|
||||
print(row,col)
|
||||
|
||||
if get_value_in_direction(grid,(row,col)) == current_node and (row,col) != pos:
|
||||
print('Matched with',(row,col))
|
||||
|
||||
s = subTuples((row,col-1),pos)
|
||||
a = addTuples(s,(row,col+1))
|
||||
if grid_valid(s[0],s[1],grid):
|
||||
print('Antinode at',s)
|
||||
antinodes.append(s)
|
||||
if grid_valid(a[0],a[1],grid):
|
||||
print('Antinode at',a)
|
||||
antinodes.append(a)
|
||||
|
||||
return antinodes
|
||||
|
||||
if part == 1:
|
||||
grid = toGrid(input_f)
|
||||
|
||||
nprint(grid)
|
||||
|
||||
size = (len(grid),len(grid[0]))
|
||||
antinodes = []
|
||||
for row in range(0,size[0]):
|
||||
for col in range(0,size[1]):
|
||||
current_node = get_value_in_direction(grid,(row,col))
|
||||
if current_node != '.':
|
||||
antinodes += findAntinodes(grid,(row,col),current_node)
|
||||
print(antinodes)
|
||||
for idx, i in enumerate(grid):
|
||||
for jdx, j in enumerate(i):
|
||||
if (idx, jdx) in antinodes:
|
||||
print('#', end=' ') # Print sign
|
||||
else:
|
||||
print(grid[idx][jdx], end=' ') # Regular grid element
|
||||
print()
|
||||
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
if part == 2:
|
||||
exit()
|
||||
|
||||
print("--- %s seconds ---" % (time.time() - start_time))
|
12
2024/08/test2
Normal file
12
2024/08/test2
Normal file
@ -0,0 +1,12 @@
|
||||
............
|
||||
........0...
|
||||
.....0......
|
||||
.......0....
|
||||
....0.......
|
||||
......A.....
|
||||
............
|
||||
............
|
||||
........A...
|
||||
.........A..
|
||||
............
|
||||
............
|
@ -103,7 +103,7 @@
|
||||
//|
|
||||
|
||||
## 2015
|
||||
|
||||
>>O>@>>>o>>>*>>*>>>@<<O>>@<<<@<O< 9 **
|
||||
>>*<*<<<o<@>>o<*<<<*<<o>>O>>>*>*<<< 8 **
|
||||
|
||||
>@>o<O>>O<<<O>>>*>>*<*>>*<O<<o<<<O>>@<< 6 **
|
||||
|
Binary file not shown.
18
fred.py
18
fred.py
@ -122,6 +122,24 @@ def addTuples(x: tuple, y: tuple):
|
||||
raise TypeError("Both inputs must be tuples.")
|
||||
return (x[0] + y[0], x[1] + y[1])
|
||||
|
||||
def subTuples(x: tuple, y: tuple):
|
||||
"""
|
||||
Substracts two tuples element-wise.
|
||||
|
||||
Args:
|
||||
x (tuple): The first tuple.
|
||||
y (tuple): The second tuple.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple with the sum of corresponding elements of x and y.
|
||||
|
||||
Raises:
|
||||
TypeError: If x or y are not tuples.
|
||||
"""
|
||||
if not isinstance(x, tuple) or not isinstance(y, tuple):
|
||||
raise TypeError("Both inputs must be tuples.")
|
||||
return (x[0] - y[0], x[1] - y[1])
|
||||
|
||||
def findDupes(input: list):
|
||||
"""
|
||||
Finds duplicate elements in a list and returns their values.
|
||||
|
Loading…
Reference in New Issue
Block a user