main.py 946 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. from doctest import Example
  2. import os, sys
  3. import numpy as np
  4. task_dir = os.path.dirname(__file__)
  5. sys.path.append(f"{task_dir}/..")
  6. from get_tasks import get_input, check_example, generate_readme
  7. def grow(input: list[str], days) -> int:
  8. # parse data to array with days
  9. state = np.fromstring(input[0], sep=",", dtype=int)
  10. counts = np.zeros(9, dtype=int)
  11. day_left, count = np.unique(state, return_counts=1)
  12. counts[day_left] += count
  13. for day in range(days):
  14. counts[(day + 7) % 9] += counts[day % 9]
  15. return counts.sum()
  16. def part1(input: list[str]):
  17. print('The answer of part1 is:', grow(input, 80))
  18. def part2(input: list[str]):
  19. print('The answer of part2 is:', grow(input, 256))
  20. if __name__ == "__main__":
  21. input, example = get_input(task_dir, 6)
  22. check_example(example, part1)
  23. check_example(example, part2)
  24. part1(input)
  25. part2(input)
  26. generate_readme(task_dir, 6)