Compare commits
2 Commits
adea09622c
...
ac2a79d085
Author | SHA1 | Date | |
---|---|---|---|
ac2a79d085 | |||
a3a7d201b3 |
@ -89,8 +89,6 @@ first two numbers in the list*?
|
||||
|
||||
Your puzzle answer was `19591`.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: \*
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
The logic you\'ve constructed forms a single *round* of the *Knot Hash*
|
||||
@ -163,7 +161,13 @@ Treating your puzzle input as a string of ASCII characters, *what is the
|
||||
Knot Hash of your puzzle input?* Ignore any leading or trailing
|
||||
whitespace you might encounter.
|
||||
|
||||
Answer:
|
||||
Your puzzle answer was `62e2204d2ca4f4924f6e7a80f1288786`.
|
||||
|
||||
Although it hasn\'t changed, you can still [get your puzzle
|
||||
Both parts of this puzzle are complete! They provide two gold stars:
|
||||
\*\*
|
||||
|
||||
At this point, you should [return to your Advent calendar](/2017) and
|
||||
try another puzzle.
|
||||
|
||||
If you still want to see it, you can [get your puzzle
|
||||
input](10/input).
|
||||
|
@ -1,13 +1,23 @@
|
||||
#!/bin/python3
|
||||
import sys,re
|
||||
from pprint import pprint
|
||||
from functools import reduce
|
||||
from operator import xor
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
def list2int(x):
|
||||
return list(map(int, x))
|
||||
|
||||
part = 1
|
||||
def toACSII(x):
|
||||
for idx,i in enumerate(x):
|
||||
x[idx] = ord(i)
|
||||
return x
|
||||
|
||||
def XOR(x):
|
||||
return reduce(xor, map(int, t))
|
||||
|
||||
part = 2
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
@ -46,4 +56,42 @@ if part == 1:
|
||||
# #
|
||||
#########################################
|
||||
if part == 2:
|
||||
exit()
|
||||
|
||||
size = 256
|
||||
lengths = []
|
||||
skip = 0
|
||||
numbers = []
|
||||
pos = 0
|
||||
for i in range(0,size):
|
||||
numbers.append(i)
|
||||
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
lengths = list(line.rsplit()[0].split()[0])
|
||||
lengths = toACSII(lengths) + [17, 31, 73, 47, 23]
|
||||
print(lengths)
|
||||
|
||||
for i in range(0,64):
|
||||
for ldx, length in enumerate(lengths):
|
||||
sub = [numbers[(pos + i) % len(numbers)] for i in range(length)]
|
||||
rev = sub[::-1]
|
||||
|
||||
for i in range(length):
|
||||
numbers[(pos + i) % len(numbers)] = rev[i]
|
||||
|
||||
pos += (length+skip)
|
||||
pos = pos % len(numbers)
|
||||
skip += 1
|
||||
print(numbers)
|
||||
|
||||
dense = []
|
||||
|
||||
for i in range(0,16):
|
||||
t = numbers[i*16:(i*16)+16]
|
||||
dense.append(XOR(t))
|
||||
|
||||
|
||||
for i in dense:
|
||||
print(format(i, '02x'),end='')
|
||||
print()
|
||||
|
1
2017/10/test2
Normal file
1
2017/10/test2
Normal file
@ -0,0 +1 @@
|
||||
1,2,3
|
1
2017/10/test3
Normal file
1
2017/10/test3
Normal file
@ -0,0 +1 @@
|
||||
1,2,4
|
52
2017/11/11.md
Normal file
52
2017/11/11.md
Normal file
@ -0,0 +1,52 @@
|
||||
## \-\-- Day 11: Hex Ed \-\--
|
||||
|
||||
Crossing the bridge, you\'ve barely reached the other side of the stream
|
||||
when a program comes up to you, clearly in distress. \"It\'s my child
|
||||
process,\" she says, \"he\'s gotten lost in an infinite grid!\"
|
||||
|
||||
Fortunately for her, you have plenty of experience with infinite grids.
|
||||
|
||||
Unfortunately for you, it\'s a [hex
|
||||
grid](https://en.wikipedia.org/wiki/Hexagonal_tiling).
|
||||
|
||||
The hexagons (\"hexes\") in [this
|
||||
grid]{title="Raindrops on roses and whiskers on kittens."} are aligned
|
||||
such that adjacent hexes can be found to the north, northeast,
|
||||
southeast, south, southwest, and northwest:
|
||||
|
||||
\ n /
|
||||
nw +--+ ne
|
||||
/ \
|
||||
-+ +-
|
||||
\ /
|
||||
sw +--+ se
|
||||
/ s \
|
||||
|
||||
You have the path the child process took. Starting where he started, you
|
||||
need to determine the fewest number of steps required to reach him. (A
|
||||
\"step\" means to move from the hex you are in to any adjacent hex.)
|
||||
|
||||
For example:
|
||||
|
||||
- `ne,ne,ne` is `3` steps away.
|
||||
- `ne,ne,sw,sw` is `0` steps away (back where you started).
|
||||
- `ne,ne,s,s` is `2` steps away (`se,se`).
|
||||
- `se,sw,se,sw,sw` is `3` steps away (`s,s,sw`).
|
||||
|
||||
Your puzzle answer was `675`.
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
*How many steps away* is the *furthest* he ever got from his starting
|
||||
position?
|
||||
|
||||
Your puzzle answer was `1424`.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars:
|
||||
\*\*
|
||||
|
||||
At this point, you should [return to your Advent calendar](/2017) and
|
||||
try another puzzle.
|
||||
|
||||
If you still want to see it, you can [get your puzzle
|
||||
input](11/input).
|
98
2017/11/solution.py
Normal file
98
2017/11/solution.py
Normal file
@ -0,0 +1,98 @@
|
||||
#!/bin/python3
|
||||
import sys,re,math
|
||||
from pprint import pprint
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
part = 2
|
||||
|
||||
def manhattan(a, b):
|
||||
return int(sum(abs(val1-val2) for val1, val2 in zip(a,b))/2)
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
# https://www.redblobgames.com/grids/hexagons/
|
||||
|
||||
if part == 1:
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
steps = line.rsplit()[0].split(',')
|
||||
#print(steps)
|
||||
|
||||
grid = []
|
||||
|
||||
w, h = 11,11
|
||||
grid = [[' ' for x in range(w)] for y in range(h)]
|
||||
|
||||
|
||||
start = int(len(grid)/2)
|
||||
distance = []
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
z = 0
|
||||
|
||||
for i in steps:
|
||||
if i == 'ne':
|
||||
x += 1
|
||||
z -= 1
|
||||
if i == 'sw':
|
||||
x -= 1
|
||||
z += 1
|
||||
if i == 's':
|
||||
z += 1
|
||||
y -= 1
|
||||
if i == 'n':
|
||||
z -= 1
|
||||
y += 1
|
||||
if i == 'se':
|
||||
x += 1
|
||||
y -= 1
|
||||
if i == 'nw':
|
||||
x -= 1
|
||||
y += 1
|
||||
print(int((abs(x)+abs(y)+abs(z))/2))
|
||||
|
||||
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
if part == 2:
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
steps = line.rsplit()[0].split(',')
|
||||
|
||||
distance = []
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
z = 0
|
||||
|
||||
for i in steps:
|
||||
if i == 'ne':
|
||||
x += 1
|
||||
z -= 1
|
||||
if i == 'sw':
|
||||
x -= 1
|
||||
z += 1
|
||||
if i == 's':
|
||||
z += 1
|
||||
y -= 1
|
||||
if i == 'n':
|
||||
z -= 1
|
||||
y += 1
|
||||
if i == 'se':
|
||||
x += 1
|
||||
y -= 1
|
||||
if i == 'nw':
|
||||
x -= 1
|
||||
y += 1
|
||||
distance.append((abs(x)+abs(y)+abs(z))/2)
|
||||
|
||||
print('Distance:',int(max(distance)))
|
Loading…
Reference in New Issue
Block a user