Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

123456789101112131415161718192021222324252627282930
  1. def main():
  2. """ Consider three-depth windows instead of individual depths:
  3. 199 A
  4. 200 A B
  5. 208 A B C
  6. 210 B C D
  7. 200 E C D
  8. 207 E F D
  9. 240 E F G
  10. 269 F G H
  11. 260 G H
  12. 263 H
  13. For each window in the list, determine whether it's deeper than the previous window.
  14. There is no previous depth for the first entry.
  15. Output the total number of times the depth increased.
  16. """
  17. with open("aoc1-1.txt", "r") as file:
  18. depths = file.readlines()
  19. depths = [int(el.strip()) for el in depths]
  20. prev = 999999999
  21. increases = []
  22. for i in range(len(depths)-2):
  23. window = depths[i] + depths[i+1] + depths[i+2]
  24. increases.append(1 if window > prev else 0)
  25. prev = window
  26. print(sum(increases))
  27. if __name__ == "__main__":
  28. main()