feat: complete part one
This commit is contained in:
45
2020/day06/main.go
Normal file
45
2020/day06/main.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func parseInput(file string) []string {
|
||||||
|
content, err := os.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to read input file: %v", err)
|
||||||
|
}
|
||||||
|
return strings.Split(strings.TrimSpace(string(content)), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func PartOne(input []string) int {
|
||||||
|
total := 0
|
||||||
|
groupAnswers := make(map[rune]bool)
|
||||||
|
|
||||||
|
for i, line := range input {
|
||||||
|
if line != "" {
|
||||||
|
for _, char := range line {
|
||||||
|
if char >= 'a' && char <= 'z' {
|
||||||
|
groupAnswers[char] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if line == "" || i == len(input)-1 {
|
||||||
|
total += len(groupAnswers)
|
||||||
|
groupAnswers = make(map[rune]bool)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total += len(groupAnswers)
|
||||||
|
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
input := parseInput("input.txt")
|
||||||
|
fmt.Println("Part 1:", PartOne(input))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user