Solutions to Advent of Code 2017 https://adventofcode.com/2017/
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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)}')