From c8a81ebec25fd3c054c708d542f0bcc11810756a Mon Sep 17 00:00:00 2001 From: plasmaofthedawn Date: Sat, 2 Dec 2023 02:18:20 -0500 Subject: [PATCH] added one liner python codes to flex --- pythonsrc/day1/part1.py | 5 +++++ pythonsrc/day1/part2.py | 14 ++++++++++++++ pythonsrc/day2/part1.py | 14 ++++++++++++++ pythonsrc/day2/part2.py | 12 ++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 pythonsrc/day1/part1.py create mode 100644 pythonsrc/day1/part2.py create mode 100644 pythonsrc/day2/part1.py create mode 100644 pythonsrc/day2/part2.py diff --git a/pythonsrc/day1/part1.py b/pythonsrc/day1/part1.py new file mode 100644 index 0000000..be07a93 --- /dev/null +++ b/pythonsrc/day1/part1.py @@ -0,0 +1,5 @@ +print( + sum([a[0]*10 + a[-1] for a in [[int(b) for b in c if b.isnumeric()] for c in open('resources/day1.txt').read().split("\n")[:-1]]]) +) + +# sum([a[0]*10 + a[-1] for a in [[int(b) for b in c if b.isnumeric()] for c in open('resources/day1.txt').read().split("\n")[:-1]]]) \ No newline at end of file diff --git a/pythonsrc/day1/part2.py b/pythonsrc/day1/part2.py new file mode 100644 index 0000000..52ec9cf --- /dev/null +++ b/pythonsrc/day1/part2.py @@ -0,0 +1,14 @@ + +print( + sum( + [a[0]*10 + a[-1] for a in + [ + [int(b) for b in c.replace("eight", "e8t").replace("two", "2o").replace("one", "1").replace("five", "5").replace("seven", "7n") + .replace("nine", "9").replace("six", '6').replace("four", "4").replace("three", "3") if b.isnumeric() + ] for c in open('resources/day1.txt').read().split("\n")[:-1] + ] + ] + ) +) + + # sum([a[0]*10 + a[-1] for a in [[int(b) for b in c.replace("eight", "e8t").replace("two", "2o").replace("one", "1").replace("five", "5").replace("seven", "7n").replace("nine", "9").replace("six", '6').replace("four", "4").replace("three", "3") if b.isnumeric()] for c in open('resources/day1.txt').read().split("\n")[:-1]]]) \ No newline at end of file diff --git a/pythonsrc/day2/part1.py b/pythonsrc/day2/part1.py new file mode 100644 index 0000000..726325b --- /dev/null +++ b/pythonsrc/day2/part1.py @@ -0,0 +1,14 @@ + +print( + sum([ + (y+1) * (0 if + ( + sum([int(x.split(" ")[0]) > 12 for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'red' in x]) + + sum([int(x.split(" ")[0]) > 13 for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'green' in x]) + + sum([int(x.split(" ")[0]) > 14 for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'blue' in x]) + ) > 0 else 1) + for y, z in enumerate(open('resources/day2.txt').readlines()) + ]) +) + +# sum([(y+1) * (0 if (sum([int(x.split(" ")[0]) > 12 for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'red' in x]) + sum([int(x.split(" ")[0]) > 13 for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'green' in x]) + sum([int(x.split(" ")[0]) > 14 for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'blue' in x])) > 0 else 1) for y, z in enumerate(open('resources/day2.txt').readlines())]) \ No newline at end of file diff --git a/pythonsrc/day2/part2.py b/pythonsrc/day2/part2.py new file mode 100644 index 0000000..da6d81c --- /dev/null +++ b/pythonsrc/day2/part2.py @@ -0,0 +1,12 @@ +print( + sum( + [ + max([int(x.split(" ")[0]) for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'red' in x]) * + max([int(x.split(" ")[0]) for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'green' in x]) * + max([int(x.split(" ")[0]) for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'blue' in x]) + for z in open('resources/day2.txt').readlines() + ] + ) +) + +# sum([max([int(x.split(" ")[0]) for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'red' in x]) * max([int(x.split(" ")[0]) for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'green' in x]) * max([int(x.split(" ")[0]) for x in z.split(": ")[1][:-1].replace(";", ",").split(", ") if 'blue' in x]) for z in open('resources/day2.txt').readlines()]) \ No newline at end of file