updated repo layout

This commit is contained in:
2021-12-16 19:55:49 +00:00
parent 9f4bdcf271
commit 90bc7c683d
47 changed files with 20 additions and 20 deletions

53
day06/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
}

71
day06/6b/main.go Normal file
View File

@ -0,0 +1,71 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
content := returnContent("../input")
//content := returnContent("testInput")
fmt.Println(content)
days := 256
var waitTime [9]int
for _, v := range *content {
waitTime[v]++
}
fmt.Println(waitTime)
for gen := 0; gen < days; gen++ {
justBred := waitTime[0]
for daysToWait := range waitTime[:len(waitTime)-1] {
//Move array down a position
waitTime[daysToWait] = waitTime[daysToWait+1]
}
//Add new fish and fish that have just bred (fallen off end of array)
waitTime[6] += justBred //start waiting other 6 days
waitTime[8] = justBred //new fishes
}
var numFishes int
for _, fishes := range waitTime {
numFishes += fishes
}
fmt.Println(numFishes)
}
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
day06/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

1
day06/testInput Normal file
View File

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