Since everyone wanted me to use lists for D1, here you go

Also, zombie, your PR kinda sucked so I deleted it and made my own
This commit is contained in:
Logan G 2022-12-03 15:39:19 -07:00
parent b76699fca6
commit ae592b71af
Signed by: logan
GPG key ID: E328528C921E7A7A
3 changed files with 89 additions and 11 deletions

22
day1/day1-alt.py Normal file
View file

@ -0,0 +1,22 @@
if __name__ == "__main__":
elves = []
with open('input', 'r') as f:
sum_ = 0
for line in f:
if line.strip() == '':
elves.append(sum_)
sum_ = 0
else:
sum_ += int(line.strip())
elves.append(sum_)
elves.sort(reverse=True)
largest = elves[0]
print(f'Max Value: {largest}')
top3 = elves[0] + elves[1] + elves[2]
print(f'Top 3: {top3}')

View file

@ -1,23 +1,24 @@
if __name__ == "__main__":
elves = {}
elves = []
with open('input', 'r') as f:
elf = 0
elves[0] = 0
sum_ = 0
for line in f:
if line.strip() == '':
elf += 1
elves[elf] = 0
elves.append(sum_)
sum_ = 0
else:
elves[elf] += int(line.strip())
sum_ += int(line.strip())
largest = max(elves, key=elves.get)
print(f'Index: {largest}\nValue: {elves[largest]}')
elves.append(sum_)
largest = max(elves)
print(f'Max Value: {largest}')
top3 = 0
for i in range(3):
largest = max(elves, key=elves.get)
top3 += elves[largest]
del elves[largest]
largest = max(elves)
top3 += largest
elves.remove(largest)
print(f'Top 3: {top3}')

55
day1/input2 Normal file
View file

@ -0,0 +1,55 @@
5324
5176
2197
2701
6185
3901
5392
2065
6467
6085
5062
1841
1197
1318
4901
3443
1403
5570
4336
5672
2532
5627
6038
1099
4305
2317
1382
3226
4427
2612
15638
4118
4687
2243
3532
2089
3937
1146
5069
5728
2962
3099
5882
5448
6064
2642
7996
5334
10384
1106
2742