From 77fd77b4cb2c0b922bf363e446363a0a86372189 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Mon, 6 Dec 2021 21:29:14 +0000 Subject: [PATCH] day 6a complete --- day6/day 6a/go.mod | 3 +++ day6/day 6a/main.go | 53 +++++++++++++++++++++++++++++++++++++++++++ day6/day 6a/testInput | 1 + day6/input | 1 + 4 files changed, 58 insertions(+) create mode 100644 day6/day 6a/go.mod create mode 100644 day6/day 6a/main.go create mode 100644 day6/day 6a/testInput create mode 100644 day6/input diff --git a/day6/day 6a/go.mod b/day6/day 6a/go.mod new file mode 100644 index 0000000..e938e2e --- /dev/null +++ b/day6/day 6a/go.mod @@ -0,0 +1,3 @@ +module PWD + +go 1.17 diff --git a/day6/day 6a/main.go b/day6/day 6a/main.go new file mode 100644 index 0000000..9420d46 --- /dev/null +++ b/day6/day 6a/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +func main() { + content := returnContent("../input") + //content := returnContent("testInput") + fmt.Println(content) + + days := 80 + + for i := 0; i < days; i++ { + for j := 0; j < len(*content); j++ { + (*content)[j]-- + if (*content)[j] < 0 { + (*content)[j] = 6 + (*content) = append((*content), 9) + } + } + } + + fmt.Println(len(*content)) +} + +func returnContent(path string) *[]int { + //read file and return it as an array of integers + + file, err := os.Open(path) + var content []int + + if err != nil { + fmt.Println("Unlucky, the file didn't open") + return &content + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + text := strings.Split(scanner.Text(), ",") + for _, v := range text { + num, _ := strconv.Atoi(v) + content = append(content, num) + } + } + + return &content +} diff --git a/day6/day 6a/testInput b/day6/day 6a/testInput new file mode 100644 index 0000000..a7af2b1 --- /dev/null +++ b/day6/day 6a/testInput @@ -0,0 +1 @@ +3,4,3,1,2 \ No newline at end of file diff --git a/day6/input b/day6/input new file mode 100644 index 0000000..89b026d --- /dev/null +++ b/day6/input @@ -0,0 +1 @@ +1,1,1,2,1,1,2,1,1,1,5,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,4,1,1,1,1,3,1,1,3,1,1,1,4,1,5,1,3,1,1,1,1,1,5,1,1,1,1,1,5,5,2,5,1,1,2,1,1,1,1,3,4,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,5,4,1,1,1,1,1,5,1,2,4,1,1,1,1,1,3,3,2,1,1,4,1,1,5,5,1,1,1,1,1,2,5,1,4,1,1,1,1,1,1,2,1,1,5,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,3,1,1,3,1,3,1,4,1,5,4,1,1,2,1,1,5,1,1,1,1,1,5,1,1,1,1,1,1,1,1,1,4,1,1,4,1,1,1,1,1,1,1,5,4,1,2,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,4,1,1,1,2,1,4,1,1,1,1,1,1,1,1,1,4,2,1,2,1,1,4,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,3,2,1,4,1,5,1,1,1,4,5,1,1,1,1,1,1,5,1,1,5,1,2,1,1,2,4,1,1,2,1,5,5,3 \ No newline at end of file