aoc2023/day-3/util.go

35 lines
527 B
Go
Raw Normal View History

2023-12-03 23:57:05 +00:00
package main
import (
"bufio"
"log"
"os"
)
// readlines reads lines from stdin.
// Then it returns them as an array of strings
func readlines() []string {
lines := []string{}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return lines
}
// anyTrue checks if any digits passed
func anyTrue(digits []digit) bool {
for _, digit := range digits {
if digit.pass {
return true
}
}
return false
}