aboutsummaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2021/06/example1
-rw-r--r--2021/06/first.go34
-rw-r--r--2021/06/input1
-rw-r--r--2021/06/second.go34
4 files changed, 70 insertions, 0 deletions
diff --git a/2021/06/example b/2021/06/example
new file mode 100644
index 0000000..55129f1
--- /dev/null
+++ b/2021/06/example
@@ -0,0 +1 @@
+3,4,3,1,2
diff --git a/2021/06/first.go b/2021/06/first.go
new file mode 100644
index 0000000..efb77be
--- /dev/null
+++ b/2021/06/first.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+)
+
+func main() {
+ g := make([]int, 9)
+
+ s := bufio.NewReader(os.Stdin)
+ for {
+ buf := make([]byte, 2)
+ if n, _ := s.Read(buf); n == 0 {
+ break
+ }
+ g[buf[0]-'0']++
+ }
+ for d := 0; d <= 80; d++ {
+ fmt.Printf("%+v\n", g)
+ n := g[0]
+ for i := 0; i < 8; i++ {
+ g[i] = g[i+1]
+ }
+ g[6] += n
+ g[8] = n
+ }
+ total := 0
+ for i := 0; i < 8; i++ {
+ total += g[i]
+ }
+ fmt.Printf("%d\n", total)
+}
diff --git a/2021/06/input b/2021/06/input
new file mode 100644
index 0000000..445de95
--- /dev/null
+++ b/2021/06/input
@@ -0,0 +1 @@
+1,1,3,1,3,2,1,3,1,1,3,1,1,2,1,3,1,1,3,5,1,1,1,3,1,2,1,1,1,1,4,4,1,2,1,2,1,1,1,5,3,2,1,5,2,5,3,3,2,2,5,4,1,1,4,4,1,1,1,1,1,1,5,1,2,4,3,2,2,2,2,1,4,1,1,5,1,3,4,4,1,1,3,3,5,5,3,1,3,3,3,1,4,2,2,1,3,4,1,4,3,3,2,3,1,1,1,5,3,1,4,2,2,3,1,3,1,2,3,3,1,4,2,2,4,1,3,1,1,1,1,1,2,1,3,3,1,2,1,1,3,4,1,1,1,1,5,1,1,5,1,1,1,4,1,5,3,1,1,3,2,1,1,3,1,1,1,5,4,3,3,5,1,3,4,3,3,1,4,4,1,2,1,1,2,1,1,1,2,1,1,1,1,1,5,1,1,2,1,5,2,1,1,2,3,2,3,1,3,1,1,1,5,1,1,2,1,1,1,1,3,4,5,3,1,4,1,1,4,1,4,1,1,1,4,5,1,1,1,4,1,3,2,2,1,1,2,3,1,4,3,5,1,5,1,1,4,5,5,1,1,3,3,1,1,1,1,5,5,3,3,2,4,1,1,1,1,1,5,1,1,2,5,5,4,2,4,4,1,1,3,3,1,5,1,1,1,1,1,1
diff --git a/2021/06/second.go b/2021/06/second.go
new file mode 100644
index 0000000..c64aa61
--- /dev/null
+++ b/2021/06/second.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+)
+
+func main() {
+ g := make([]int, 9)
+
+ s := bufio.NewReader(os.Stdin)
+ for {
+ buf := make([]byte, 2)
+ if n, _ := s.Read(buf); n == 0 {
+ break
+ }
+ g[buf[0]-'0']++
+ }
+ for d := 0; d <= 256; d++ {
+ fmt.Printf("%+v\n", g)
+ n := g[0]
+ for i := 0; i < 8; i++ {
+ g[i] = g[i+1]
+ }
+ g[6] += n
+ g[8] = n
+ }
+ total := 0
+ for i := 0; i < 8; i++ {
+ total += g[i]
+ }
+ fmt.Printf("%d\n", total)
+}