-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (59 loc) · 1.8 KB
/
main.go
File metadata and controls
73 lines (59 loc) · 1.8 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"bufio"
"fmt"
"io"
"os"
"path"
"strings"
)
func input() *os.File {
input, err := os.Open(path.Join("2021", "8", "input.txt"))
if err != nil {
panic(err)
}
return input
}
type record struct {
patterns []string
output []string
}
func parse(r io.Reader) []record {
scanner := bufio.NewScanner(r)
var records []record
for scanner.Scan() {
line := scanner.Text()
parts := strings.Split(line, " | ")
records = append(records, record{
patterns: strings.Split(parts[0], " "),
output: strings.Split(parts[1], " "),
})
}
if scanner.Err() != nil {
panic(scanner.Err())
}
return records
}
func solve(r io.Reader) {
records := parse(r)
sum := 0
for _, record := range records {
for _, digit := range record.output {
switch len(digit) {
case 2:
fallthrough
case 3:
fallthrough
case 4:
fallthrough
case 7:
sum += 1
}
}
}
fmt.Println(sum)
}
func main() {
solve(strings.NewReader("be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe\nedbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc\nfgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg\nfbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb\naecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea\nfgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb\ndbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe\nbdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef\negadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb\ngcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce"))
solve(input())
}