06: part1+2
This commit is contained in:
parent
b93d14ad5b
commit
7518efc103
4 changed files with 74 additions and 0 deletions
1
6/input
Normal file
1
6/input
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3,1,5,4,4,4,5,3,4,4,1,4,2,3,1,3,3,2,3,2,5,1,1,4,4,3,2,4,2,4,1,5,3,3,2,2,2,5,5,1,3,4,5,1,5,5,1,1,1,4,3,2,3,3,3,4,4,4,5,5,1,3,3,5,4,5,5,5,1,1,2,4,3,4,5,4,5,2,2,3,5,2,1,2,4,3,5,1,3,1,4,4,1,3,2,3,2,4,5,2,4,1,4,3,1,3,1,5,1,3,5,4,3,1,5,3,3,5,4,2,3,4,1,2,1,1,4,4,4,3,1,1,1,1,1,4,2,5,1,1,2,1,5,3,4,1,5,4,1,3,3,1,4,4,5,3,1,1,3,3,3,1,1,5,4,2,5,1,1,5,5,1,4,2,2,5,3,1,1,3,3,5,3,3,2,4,3,2,5,2,5,4,5,4,3,2,4,3,5,1,2,2,4,3,1,5,5,1,3,1,3,2,2,4,5,4,2,3,2,3,4,1,3,4,2,5,4,4,2,2,1,4,1,5,1,5,4,3,3,3,3,3,5,2,1,5,5,3,5,2,1,1,4,2,2,5,1,4,3,3,4,4,2,3,2,1,3,1,5,2,1,5,1,3,1,4,2,4,5,1,4,5,5,3,5,1,5,4,1,3,4,1,1,4,5,5,2,1,3,3
|
33
6/part1.go
Normal file
33
6/part1.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var fishes []int
|
||||||
|
|
||||||
|
s := bufio.NewScanner(os.Stdin)
|
||||||
|
s.Scan()
|
||||||
|
for _, fishStr := range strings.Split(s.Text(), ",") {
|
||||||
|
fish, _ := strconv.Atoi(fishStr)
|
||||||
|
fishes = append(fishes, fish)
|
||||||
|
}
|
||||||
|
|
||||||
|
for x := 0; x < 80; x++ {
|
||||||
|
for i := range fishes {
|
||||||
|
if fishes[i] == 0 {
|
||||||
|
fishes[i] = 6
|
||||||
|
fishes = append(fishes, 8)
|
||||||
|
} else {
|
||||||
|
fishes[i]--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(len(fishes))
|
||||||
|
}
|
39
6/part2.go
Normal file
39
6/part2.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// https://en.wiktionary.org/wiki/fishes#English
|
||||||
|
fishes := map[int]int{}
|
||||||
|
|
||||||
|
s := bufio.NewScanner(os.Stdin)
|
||||||
|
s.Scan()
|
||||||
|
for _, fishStr := range strings.Split(s.Text(), ",") {
|
||||||
|
fish, _ := strconv.Atoi(fishStr)
|
||||||
|
fishes[fish]++
|
||||||
|
}
|
||||||
|
|
||||||
|
for x := 0; x < 256; x++ {
|
||||||
|
newFishes := map[int]int{}
|
||||||
|
// handle usual decrements
|
||||||
|
for i := 8; i > 0; i-- {
|
||||||
|
newFishes[i-1] = fishes[i]
|
||||||
|
}
|
||||||
|
// handle the new fishes
|
||||||
|
newFishes[6] += fishes[0]
|
||||||
|
newFishes[8] += fishes[0]
|
||||||
|
fishes = newFishes
|
||||||
|
}
|
||||||
|
|
||||||
|
sum := 0
|
||||||
|
for _, count := range fishes {
|
||||||
|
sum += count
|
||||||
|
}
|
||||||
|
fmt.Println(sum)
|
||||||
|
}
|
1
6/testinput
Normal file
1
6/testinput
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3,4,3,1,2
|
Loading…
Reference in a new issue