day 6a complete

This commit is contained in:
Luke Else 2021-12-06 21:29:14 +00:00
parent 6469a6037c
commit 77fd77b4cb
4 changed files with 58 additions and 0 deletions

3
day6/day 6a/go.mod Normal file
View File

@ -0,0 +1,3 @@
module PWD
go 1.17

53
day6/day 6a/main.go Normal file
View File

@ -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
}

1
day6/day 6a/testInput Normal file
View File

@ -0,0 +1 @@
3,4,3,1,2

1
day6/input Normal file
View File

@ -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