Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1.     1 with open('files/puzzle10.txt') as f:
  2.     2     blep = f.read()
  3.     3     puzzle_input = [int(c) for c in blep.split(',')]
  4.     4     puzzle_ascii = [ord(c) for c in blep[:len(blep) - 1]]
  5.     5     puzzle_ascii.extend([17, 31, 73, 47, 23])
  6.     6
  7.     7 def round(this_input, this_list, skip, pos):
  8.     8     for length in this_input:
  9.     9         twist = reversed([this_list[i % len(this_list)] for i in range(pos[0], pos[0] + length)])
  10.    10         for i, t in zip(range(pos[0], pos[0] + length), twist):
  11.    11             this_list[i % len(this_list)] = t
  12.    12         pos[0] += length + skip[0]
  13.    13         skip[0] += 1
  14.    14
  15.    15 my_list = [i for i in range(256)]
  16.    16 round(puzzle_input, my_list, [0], [0])
  17.    17 print my_list[0] * my_list[1]
  18.    18
  19.    19 my_list = [i for i in range(256)]
  20.    20 skip, pos = [0], [0]
  21.    21
  22.    22 for i in range(64):
  23.    23     round(puzzle_ascii, my_list, skip, pos)
  24.    24
  25.    25 knot_hash = []                                                                                                                  
  26.    26
  27.    27 for block in [my_list[i:i + 16] for i in range(0, len(my_list), 16)]:
  28.    28     knot_hash.append(chr(reduce(lambda x, y: x ^ y, block)))
  29.    29
  30.    30 print "".join(knot_hash).encode("hex")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement