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

3
.gitignore vendored
View file

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

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/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")] elves = [x.split("\n") for x in f.read().split("\n\n")]
ints = [[int(j) for j in i] for i in elves] ints = [[int(j) for j in i] for i in elves]
sums = sorted([sum(i) for i in ints]) sums = sorted([sum(i) for i in ints])

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/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")] elves = [x.split("\n") for x in f.read().split("\n\n")]
ints = [[int(j) for j in i] for i in elves] ints = [[int(j) for j in i] for i in elves]
sums = sorted([sum(i) for i in ints]) 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])