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

12345678910111213141516
  1. with open('data/17.txt', 'r') as file:
  2. steps = int(file.readline().strip())
  3. buffer = []
  4. position = 0
  5. for i in range(2018):
  6. buffer.insert(position, i)
  7. position = (position + steps + 1) % (i + 1)
  8. print(f'Part one: {buffer[(buffer.index(2017) + 1) % len(buffer)]}')
  9. # The entry for zero is always at the end of our buffer, as we never call insert beyond the length of the list,
  10. # so the entry after zero is always the one at position 0.
  11. for i in range(2018, 50000001):
  12. if position == 0:
  13. after_zero = i
  14. position = (position + steps + 1) % (i + 1)
  15. print(f'Part two: {after_zero}')