diff --git a/2019/day01.py b/2019/day01.py new file mode 100644 index 0000000..9913bf4 --- /dev/null +++ b/2019/day01.py @@ -0,0 +1,25 @@ +""" https://adventofcode.com/2019/day/1 """ + +def readFile(): + import os.path as p + dName = p.dirname(__file__) + fName = p.basename(__file__).split(".")[0] + + with open(p.join(dName, "input", f"{fName}.txt"), "r") as f: + return [int(line[:-1]) for line in f.readlines()] + +def part1(vals : list): + return sum([val // 3 - 2 for val in vals]) + +def part2(vals : list): + fuel = [val // 3 - 2 for val in vals] + for f in fuel: + temp = f // 3 - 2 + if temp > 0: + fuel.append(temp) + return sum(fuel) + +if __name__ == "__main__": + vals = readFile() + print(f"Part 1: {part1(vals)}") + print(f"Part 2: {part2(vals)}") \ No newline at end of file diff --git a/2019/input/day01.txt b/2019/input/day01.txt new file mode 100644 index 0000000..fb368d2 --- /dev/null +++ b/2019/input/day01.txt @@ -0,0 +1,100 @@ +142536 +103450 +101545 +133505 +112476 +62461 +108718 +93376 +149609 +147657 +120888 +85008 +82501 +122988 +109493 +91656 +70001 +130308 +140298 +104623 +103542 +129220 +67381 +143889 +105384 +139467 +129004 +89271 +123863 +108567 +95453 +109698 +139953 +107458 +69734 +106036 +126036 +84832 +68715 +51484 +92833 +50734 +58267 +109650 +137004 +77709 +95073 +84817 +55711 +95408 +148990 +51697 +129180 +56196 +72692 +77049 +124294 +85102 +124400 +75981 +135842 +119561 +79871 +98771 +134213 +141322 +131828 +65692 +113994 +104632 +129273 +118023 +54700 +148185 +61618 +132304 +88308 +121386 +119548 +115527 +76627 +63168 +137582 +113598 +100899 +100167 +134345 +90716 +55476 +113403 +52745 +78755 +73421 +93337 +71171 +122979 +134298 +123117 +111244 +122177