選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

aoc1-1.py 568B

123456789101112131415161718
  1. def main():
  2. """ For each depth in the list, determine whether it's deeper than the previous depth.
  3. There is no previous depth for the first entry.
  4. Output the total number of times the depth increased.
  5. """
  6. with open("aoc1-1.txt", "r") as file:
  7. depths = file.readlines()
  8. depths = [int(el.strip()) for el in depths]
  9. prev = 999999999
  10. increases = []
  11. for depth in depths:
  12. increases.append(1 if depth > prev else 0)
  13. prev = depth
  14. print(sum(increases))
  15. if __name__ == "__main__":
  16. main()