From dc3a6827cd475123ad385de43297c3e91ee9e08f Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 1 Dec 2020 08:14:25 +0100 Subject: [PATCH] Add 2019 puzzle --- 2019/1/first/go.mod | 3 ++ 2019/1/first/input.txt | 100 +++++++++++++++++++++++++++++++++++ 2019/1/first/main.go | 28 ++++++++++ 2020/1/{ => first}/go.mod | 0 2020/1/{ => first}/input.txt | 0 2020/1/{ => first}/main.go | 0 6 files changed, 131 insertions(+) create mode 100644 2019/1/first/go.mod create mode 100644 2019/1/first/input.txt create mode 100644 2019/1/first/main.go rename 2020/1/{ => first}/go.mod (100%) rename 2020/1/{ => first}/input.txt (100%) rename 2020/1/{ => first}/main.go (100%) diff --git a/2019/1/first/go.mod b/2019/1/first/go.mod new file mode 100644 index 0000000..937397d --- /dev/null +++ b/2019/1/first/go.mod @@ -0,0 +1,3 @@ +module github.com/garritfra/adventofcode2019/1 + +go 1.15 diff --git a/2019/1/first/input.txt b/2019/1/first/input.txt new file mode 100644 index 0000000..6007e83 --- /dev/null +++ b/2019/1/first/input.txt @@ -0,0 +1,100 @@ +86608 +97271 +51200 +149104 +86406 +97844 +74380 +125817 +56605 +125891 +63835 +131033 +142276 +126174 +78742 +113961 +126933 +105209 +116007 +88301 +89203 +109951 +100609 +68863 +106611 +86765 +50887 +80834 +126291 +87119 +137577 +123005 +135688 +66530 +106270 +94168 +92881 +51170 +59598 +60445 +71249 +86492 +141475 +137397 +149715 +99862 +144797 +135188 +133640 +96909 +85245 +107849 +126123 +112848 +76667 +112760 +121517 +75878 +82591 +116926 +56514 +131864 +148794 +139636 +106349 +76418 +83862 +142732 +139332 +142236 +108925 +130420 +59682 +72933 +50265 +99444 +52089 +57686 +75440 +51043 +149777 +108662 +146667 +90802 +147235 +91776 +76203 +67766 +68173 +103707 +54682 +145674 +135349 +58766 +92270 +126388 +111236 +69184 +66915 +117342 \ No newline at end of file diff --git a/2019/1/first/main.go b/2019/1/first/main.go new file mode 100644 index 0000000..101f281 --- /dev/null +++ b/2019/1/first/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "io/ioutil" + "math" + "strconv" + "strings" +) + +func main() { + data, err := ioutil.ReadFile("input.txt") + if err != nil { + fmt.Println("File reading error", err) + return + } + lines := strings.Split(string(data), "\n") + + sum := 0.0 + + for _, line := range lines { + fuel, _ := strconv.Atoi(line) + result := math.Floor(float64(fuel)/3) - 2 + sum += result + } + + fmt.Println(int(sum)) +} diff --git a/2020/1/go.mod b/2020/1/first/go.mod similarity index 100% rename from 2020/1/go.mod rename to 2020/1/first/go.mod diff --git a/2020/1/input.txt b/2020/1/first/input.txt similarity index 100% rename from 2020/1/input.txt rename to 2020/1/first/input.txt diff --git a/2020/1/main.go b/2020/1/first/main.go similarity index 100% rename from 2020/1/main.go rename to 2020/1/first/main.go