浏览代码

Day 1

master
Noëlle 2 年前
父节点
当前提交
ed3c734e37
找不到此签名对应的密钥
共有 3 个文件被更改,包括 2302 次插入0 次删除
  1. 17
    0
      day1-1.py
  2. 18
    0
      day1-2.py
  3. 2267
    0
      input1.txt

+ 17
- 0
day1-1.py 查看文件

@@ -0,0 +1,17 @@
# https://adventofcode.com/2022/day/1

def main():
with open("input1.txt", "r") as file:
indata = file.read()
elves = indata.split("\n\n")

elf_cals = []
for i, elf in enumerate(elves):
cal_lines = [int(x) for x in elf.split("\n")]
elf_cals.append((i,sum(cal_lines)))
elf_cals_sorted = sorted(elf_cals, reverse=True, key=lambda x: x[1])
print(elf_cals_sorted[0])

if __name__ == "__main__":
main()

+ 18
- 0
day1-2.py 查看文件

@@ -0,0 +1,18 @@
# https://adventofcode.com/2022/day/1

def main():
with open("input1.txt", "r") as file:
indata = file.read()
elves = indata.split("\n\n")

elf_cals = []
for i, elf in enumerate(elves):
cal_lines = [int(x) for x in elf.split("\n")]
elf_cals.append((i,sum(cal_lines)))
elf_cals_sorted = sorted(elf_cals, reverse=True, key=lambda x: x[1])
most_snacks = elf_cals_sorted[:3]
print(sum([x[1] for x in most_snacks]))

if __name__ == "__main__":
main()

+ 2267
- 0
input1.txt
文件差异内容过多而无法显示
查看文件


正在加载...
取消
保存