Solutions to Advent of Code 2017 https://adventofcode.com/2017/
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.

123456789101112
  1. with open('data/01.txt', 'r') as file:
  2. captcha = file.readline().strip() * 2
  3. length = len(captcha) // 2
  4. print(f'Part one: {sum(int(captcha[i]) for i in range(length) if captcha[i] == captcha[i+1])}')
  5. print(f'Part two: {sum(int(captcha[i]) for i in range(length) if captcha[i] == captcha[i + length // 2])}')
  6. # Alternatively...
  7. import numpy as np
  8. with open('data/01.txt', 'r') as file:
  9. captcha = list(file.readline().strip())
  10. for part, roll in enumerate([1, len(captcha)//2]):
  11. print(f'Part {part+1}: {sum(int(i) for i, j in zip(captcha, np.roll(captcha, roll)) if i == j)}')