mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-21 23:56:30 +00:00
day 1
This commit is contained in:
parent
8f601de26e
commit
3623b83905
11
2019/1/README.md
Normal file
11
2019/1/README.md
Normal 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
42
2019/1/python/main.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user