advent-of-code

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 1b92a0e5b8ff9d8ba89274bb2c872c6fc9e4884e
parent 305e20b2f6c6f58c010d47551a2b075019706b92
Author: mpizzzle <michael.770211@gmail.com>
Date:   Sun, 10 Dec 2017 18:15:49 +0000

I actually figured out a lambda functiongit add .

Diffstat:
Mpuzzle10.py | 11+++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/puzzle10.py b/puzzle10.py @@ -4,9 +4,6 @@ with open('files/puzzle10.txt') as f: puzzle_ascii = [ord(c) for c in blep[:len(blep) - 1]] puzzle_ascii.extend([17, 31, 73, 47, 23]) -my_list = [i for i in range(256)] -skip, pos = [0], [0] - 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)]) @@ -15,7 +12,8 @@ def round(this_input, this_list, skip, pos): pos[0] += length + skip[0] skip[0] += 1 -round(puzzle_input, my_list, skip, pos) +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)] @@ -27,9 +25,6 @@ for i in range(64): knot_hash = [] for block in [my_list[i:i + 16] for i in range(0, len(my_list), 16)]: - value = 0 - for i in block: - value ^= i - knot_hash.append(chr(value)) + knot_hash.append(chr(reduce(lambda x, y: x ^ y, block))) print "".join(knot_hash).encode("hex")