commit acf6bc88c6278e3144618eeb6742419701d8e287 parent c34b4664c98c6bfd99ef11008ddc4df63ba6732c Author: mpizzzle <m@michaelpercival.xyz> Date: Sun, 5 Dec 2021 20:32:43 +0000 moving 2017 set into a folder Diffstat:
36 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/files/puzzle1.txt b/2017/files/puzzle1.txt diff --git a/files/puzzle10.txt b/2017/files/puzzle10.txt diff --git a/files/puzzle11.txt b/2017/files/puzzle11.txt diff --git a/files/puzzle12.txt b/2017/files/puzzle12.txt diff --git a/files/puzzle13.txt b/2017/files/puzzle13.txt diff --git a/files/puzzle15.txt b/2017/files/puzzle15.txt diff --git a/files/puzzle16.txt b/2017/files/puzzle16.txt diff --git a/files/puzzle18.txt b/2017/files/puzzle18.txt diff --git a/files/puzzle19.txt b/2017/files/puzzle19.txt diff --git a/files/puzzle2.txt b/2017/files/puzzle2.txt diff --git a/files/puzzle4.txt b/2017/files/puzzle4.txt diff --git a/files/puzzle5.txt b/2017/files/puzzle5.txt diff --git a/files/puzzle6.txt b/2017/files/puzzle6.txt diff --git a/files/puzzle7.txt b/2017/files/puzzle7.txt diff --git a/files/puzzle8.txt b/2017/files/puzzle8.txt diff --git a/files/puzzle9.txt b/2017/files/puzzle9.txt diff --git a/puzzle1.py b/2017/puzzle1.py diff --git a/2017/puzzle10.py b/2017/puzzle10.py @@ -0,0 +1,36 @@ +import sys + +with open('files/puzzle10.txt') as f: + blep = f.read() + puzzle_input = [int(c) for c in blep.split(',')] + puzzle_ascii = "" + if len(sys.argv) > 1: + puzzle_ascii = [ord(c) for c in sys.argv[1]] + else: + puzzle_ascii = [ord(c) for c in blep[:len(blep) - 1]] + puzzle_ascii.extend([17, 31, 73, 47, 23]) + +def round(this_input, this_list, skip, pos): + for length in this_input: + twist = reversed([this_list[i % len(this_list)] for i in range(pos[0], pos[0] + length)]) + for i, t in zip(range(pos[0], pos[0] + length), twist): + this_list[i % len(this_list)] = t + pos[0] += length + skip[0] + skip[0] += 1 + +my_list = [i for i in range(256)] +round(puzzle_input, my_list, [0], [0]) +#print my_list[0] * my_list[1] + +my_list = [i for i in range(256)] +skip, pos = [0], [0] + +for i in range(64): + round(puzzle_ascii, my_list, skip, pos) + +knot_hash = [] + +for block in [my_list[i:i + 16] for i in range(0, len(my_list), 16)]: + knot_hash.append(chr(reduce(lambda x, y: x ^ y, block))) + +print "".join(knot_hash).encode("base64") diff --git a/puzzle11.py b/2017/puzzle11.py diff --git a/puzzle12.py b/2017/puzzle12.py diff --git a/puzzle13.py b/2017/puzzle13.py diff --git a/puzzle14.py b/2017/puzzle14.py diff --git a/puzzle15.py b/2017/puzzle15.py diff --git a/puzzle16.py b/2017/puzzle16.py diff --git a/puzzle17.py b/2017/puzzle17.py diff --git a/puzzle18.py b/2017/puzzle18.py diff --git a/puzzle19.py b/2017/puzzle19.py diff --git a/puzzle2.py b/2017/puzzle2.py diff --git a/puzzle3.py b/2017/puzzle3.py diff --git a/puzzle4.py b/2017/puzzle4.py diff --git a/puzzle5.py b/2017/puzzle5.py diff --git a/puzzle6.py b/2017/puzzle6.py diff --git a/puzzle7.py b/2017/puzzle7.py diff --git a/puzzle8.py b/2017/puzzle8.py diff --git a/puzzle9.py b/2017/puzzle9.py diff --git a/puzzle10.py b/puzzle10.py @@ -1,36 +0,0 @@ -import sys - -with open('files/puzzle10.txt') as f: - blep = f.read() - puzzle_input = [int(c) for c in blep.split(',')] - puzzle_ascii = "" - if len(sys.argv) > 1: - puzzle_ascii = [ord(c) for c in sys.argv[1]] - else: - puzzle_ascii = [ord(c) for c in blep[:len(blep) - 1]] - puzzle_ascii.extend([17, 31, 73, 47, 23]) - -def round(this_input, this_list, skip, pos): - for length in this_input: - twist = reversed([this_list[i % len(this_list)] for i in range(pos[0], pos[0] + length)]) - for i, t in zip(range(pos[0], pos[0] + length), twist): - this_list[i % len(this_list)] = t - pos[0] += length + skip[0] - skip[0] += 1 - -my_list = [i for i in range(256)] -round(puzzle_input, my_list, [0], [0]) -print my_list[0] * my_list[1] - -my_list = [i for i in range(256)] -skip, pos = [0], [0] - -for i in range(64): - round(puzzle_ascii, my_list, skip, pos) - -knot_hash = [] - -for block in [my_list[i:i + 16] for i in range(0, len(my_list), 16)]: - knot_hash.append(chr(reduce(lambda x, y: x ^ y, block))) - -print "".join(knot_hash).encode("base64")