Added solutions for 16th day: Packet Decoder
This commit is contained in:
parent
07442255f6
commit
f169c1bbd9
14 changed files with 279 additions and 0 deletions
33
2021/16/first.go
Normal file
33
2021/16/first.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue