您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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()