Now with code golf

This commit is contained in:
Rasmus Malver 2022-12-01 17:04:52 +01:00
parent d185e7b370
commit d2744716a4
4 changed files with 16 additions and 3 deletions

5
.gitignore vendored
View file

@ -5,7 +5,8 @@
.LSOverride
# Icon must end with two \r
Icon
Icon
# Thumbnails
._*
@ -26,3 +27,5 @@ Network Trash Folder
Temporary Items
.apdisk
# Rasmus
*-dev.py

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3
with open("2022-12-01-input.txt", "r") as f:
with open("01/2022-12-01-input.txt", "r") as f:
elves = [x.split("\n") for x in f.read().split("\n\n")]
ints = [[int(j) for j in i] for i in elves]
sums = sorted([sum(i) for i in ints])

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3
with open("2022-12-01-input.txt", "r") as f:
with open("01/2022-12-01-input.txt", "r") as f:
elves = [x.split("\n") for x in f.read().split("\n\n")]
ints = [[int(j) for j in i] for i in elves]
sums = sorted([sum(i) for i in ints])

10
01/2022-12-01-golf.py Normal file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env python3
# Readable
with open("01/2022-12-01-input.txt") as f:
elves_calories = [[int(j) for j in i] for i in [x.split("\n") for x in f.read().split("\n\n")]]
print(sorted([sum(x) for x in elves_calories])[-1])
print(sum(sorted([sum(x) for x in elves_calories])[-3:]))
# One-liner
with open("01/2022-12-01-input.txt") as f: print(sorted([sum(x) for x in [[int(j) for j in i] for i in [x.split("\n") for x in f.read().split("\n\n")]]])[-1])