day 6a complete
This commit is contained in:
parent
6469a6037c
commit
77fd77b4cb
3
day6/day 6a/go.mod
Normal file
3
day6/day 6a/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module PWD
|
||||
|
||||
go 1.17
|
53
day6/day 6a/main.go
Normal file
53
day6/day 6a/main.go
Normal 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
1
day6/day 6a/testInput
Normal file
@ -0,0 +1 @@
|
||||
3,4,3,1,2
|
1
day6/input
Normal file
1
day6/input
Normal 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
|
Loading…
Reference in New Issue
Block a user