Now with code golf
This commit is contained in:
parent
d185e7b370
commit
d2744716a4
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -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
|
|
@ -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])
|
||||||
|
|
|
@ -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
10
01/2022-12-01-golf.py
Normal 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])
|
Loading…
Reference in a new issue