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.

06.py 699B

123456789101112131415161718192021222324
  1. import operator
  2. def redistribute(buckets):
  3. while True:
  4. max_index, max_value = max(enumerate(buckets), key=operator.itemgetter(1))
  5. buckets[max_index] = 0
  6. for i in range(max_value):
  7. buckets[(max_index + i + 1) % len(buckets)] += 1
  8. yield buckets
  9. def find_loop(buckets):
  10. history = [list(buckets)]
  11. for i, new_bucket in enumerate(redistribute(buckets), start=1):
  12. if new_bucket in history:
  13. return i
  14. history.append(list(buckets))
  15. with open('data/06.txt', 'r') as file:
  16. buckets = list(map(int, file.readline().split('\t')))
  17. print(f'Part one: {find_loop(buckets)}')
  18. print(f'Part two: {find_loop(buckets)}')