Advent of Code 2016 solutions https://adventofcode.com/2016/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/python3
  2. import itertools
  3. def expand(state, length):
  4. while len(state) < length:
  5. state = list(itertools.chain(state, [False], (not x for x in reversed(state))))
  6. return state[:length]
  7. def checksum_round(state):
  8. return [state[i] == state[i + 1] for i in range(0, len(state), 2)]
  9. def checksum(state):
  10. state = checksum_round(state)
  11. while len(state) % 2 == 0:
  12. state = checksum_round(state)
  13. return state
  14. def run(state, size):
  15. return ''.join(str(int(x)) for x in checksum(expand(state, size)))
  16. iv = [bool(int(x)) for x in '01110110101001000']
  17. print('Step 1: %s' % run(iv, 272))
  18. print('Step 2: %s' % run(iv, 35651584))