diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-21 22:34:30 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-21 22:34:30 +0100 |
commit | b2c570524c7371e40e21ae107f4b62790607717a (patch) | |
tree | 83279ae3155824deff2a11817d33539d07008eba | |
parent | e5c805a17a2df715bd5c4ec4cda1bbb2aa5ad4db (diff) | |
download | advent-of-code-b2c570524c7371e40e21ae107f4b62790607717a.tar.gz advent-of-code-b2c570524c7371e40e21ae107f4b62790607717a.tar.bz2 advent-of-code-b2c570524c7371e40e21ae107f4b62790607717a.zip |
Added 2019 puzzles, in python
Finished first two rounds of puzzle 1
-rw-r--r-- | 2019/puzzle-1.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/2019/puzzle-1.py b/2019/puzzle-1.py new file mode 100644 index 0000000..a6fffbd --- /dev/null +++ b/2019/puzzle-1.py @@ -0,0 +1,24 @@ +from math import floor + +def fuel(mass): + return (floor(mass / 3)) - 2 + +def read_input(): + with open("1-input", "r") as fp: + return [int(line) for line in fp.readlines()] + +def round_1(): + print(f"round 1: {sum([fuel(mass) for mass in read_input()])}") + +def recursive_fuel(mass): + new_fuel = (floor(mass / 3)) - 2 + if new_fuel <= 0: + return 0 + return new_fuel + recursive_fuel(new_fuel) + +def round_2(): + print(f"round 2: {sum([recursive_fuel(mass) for mass in read_input()])}") + +if __name__ == '__main__': + round_1() + round_2() |