AdventOfCode2021/day08/8a/main.go
2021-12-16 19:55:49 +00:00

52 lines
855 B
Go

package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
content := returnContent("../input")
//content := returnContent("../testInput")
matches := 0
for _, line := range *content {
split := strings.Split(line, " | ")
rhs := split[1]
digits := strings.Fields(rhs)
for _, digit := range digits {
segments := len(digit)
if segments == 2 || segments == 4 || segments == 3 || segments == 7 {
matches++
}
}
}
fmt.Println(matches)
}
func returnContent(path string) *[]string {
//read file and return it as an array of integers
file, err := os.Open(path)
var content []string
if err != nil {
fmt.Println("Unlucky, the file didn't open")
return &content
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
content = append(content, scanner.Text())
}
return &content
}