aboutsummaryrefslogtreecommitdiff
path: root/2021/16/first.go
blob: df0d64445ea900cfc067a5ba5d321cb16eefc42b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
}