Added solutions for 16th day: Packet Decoder

This commit is contained in:
Julien Dessaux 2021-12-16 20:49:45 +01:00
parent 07442255f6
commit f169c1bbd9
14 changed files with 279 additions and 0 deletions

33
2021/16/first.go Normal file
View file

@ -0,0 +1,33 @@
package main
import (
"bufio"
"fmt"
"os"
"git.adyxax.org/aoc/2021/16/bits"
)
var (
score = 0
)
func computeScore(b *bits.Bits) {
score += int(b.Version)
for _, sub := range b.Operators {
computeScore(sub)
}
}
func main() {
scanner := bits.NewScanner(bufio.NewReader(os.Stdin))
for {
b := scanner.Scan()
fmt.Println(b)
if b == nil {
break
}
computeScore(b)
}
fmt.Println(score)
}