From 3623b8390517809e58b6b52588e9aadbb038fe99 Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Thu, 2 Nov 2023 00:23:44 +0100 Subject: [PATCH] day 1 --- 2019/1/README.md | 11 +++++++++++ 2019/1/python/main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 2019/1/README.md create mode 100644 2019/1/python/main.py diff --git a/2019/1/README.md b/2019/1/README.md new file mode 100644 index 0000000..b94148f --- /dev/null +++ b/2019/1/README.md @@ -0,0 +1,11 @@ +# 1 + +Description + +
+ Solutions +
    +
  1. 3406527
  2. +
  3. 5106932
  4. +
+
diff --git a/2019/1/python/main.py b/2019/1/python/main.py new file mode 100644 index 0000000..f192ed0 --- /dev/null +++ b/2019/1/python/main.py @@ -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)