This commit is contained in:
Niccolo Borgioli 2023-11-02 00:23:44 +01:00
parent 8f601de26e
commit 3623b83905
No known key found for this signature in database
GPG Key ID: D93C615F75EE4F0B
2 changed files with 53 additions and 0 deletions

11
2019/1/README.md Normal file
View File

@ -0,0 +1,11 @@
# 1
Description
<details>
<summary>Solutions</summary>
<ol>
<li>3406527</li>
<li>5106932</li>
</ol>
</details>

42
2019/1/python/main.py Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env python
from os.path import join, dirname
# Day 1
# Common
def read_input(filename):
data = join(dirname(__file__), '..', filename)
with open(data) as f:
return f.read().strip()
test = read_input('test.txt')
data = read_input('input.txt')
# Running
# Part 1
def get_fuel_by_mass(mass: int):
return mass // 3 - 2
total = sum([get_fuel_by_mass(int(x)) for x in data.splitlines()])
print(total)
# Part 2
def get_fuel_by_mass_rec(mass: int):
if mass <= 6:
return 0
fuel = get_fuel_by_mass(mass)
return fuel + get_fuel_by_mass_rec(fuel)
total = sum([get_fuel_by_mass_rec(int(x)) for x in data.splitlines()])
print(total)