From 6bb9f89a4b37fd41b0568802238f45d6ef2820a7 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sun, 1 Dec 2019 00:16:49 -0500 Subject: [PATCH] Add day 1 solution --- day1/input.txt | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ day1/main.py | 25 +++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 day1/input.txt create mode 100644 day1/main.py diff --git a/day1/input.txt b/day1/input.txt new file mode 100644 index 0000000..959d909 --- /dev/null +++ b/day1/input.txt @@ -0,0 +1,100 @@ +54296 +106942 +137389 +116551 +129293 +60967 +142448 +101720 +64463 +142264 +68673 +144661 +110426 +59099 +63711 +120365 +125233 +126793 +61990 +122059 +86768 +134293 +114985 +61280 +75325 +103102 +116332 +112075 +114895 +98816 +59389 +124402 +74995 +135512 +115619 +59680 +61421 +141160 +148880 +70010 +119379 +92155 +126698 +138653 +149004 +142730 +68658 +73811 +87064 +62684 +93335 +140475 +143377 +98445 +117960 +80237 +132483 +108319 +104154 +99383 +104685 +114888 +73376 +58590 +132759 +114399 +77796 +119228 +136282 +84789 +66511 +51939 +142313 +117305 +139543 +92054 +64606 +139795 +109051 +97040 +91850 +107391 +60200 +75812 +74898 +64884 +115210 +85055 +92256 +67470 +90286 +129142 +109235 +117194 +104028 +127482 +68502 +92440 +50369 +84878 diff --git a/day1/main.py b/day1/main.py new file mode 100644 index 0000000..b6afa79 --- /dev/null +++ b/day1/main.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + + +def part1(): + with open('input.txt', 'r') as f: + print(sum(int(line)//3 - 2 for line in f)) + + +def part2(): + with open('input.txt', 'r') as f: + modules = [int(line) for line in f] + + total = 0 + for module in modules: + next_cost = module//3 - 2 + while next_cost >= 0: + total += next_cost + next_cost = next_cost // 3 - 2 + + print(total) + + +if __name__ == '__main__': + part1() + part2()