You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
aoc2020/day06/parse.go

48 lines
819 B

package day06
import (
"git.elis.nu/etu/aoc2020/utils"
)
// Build voting groups where we store tho gorup size, the question
// that got votes, and how many votes each question got.
type Group struct {
Size int
Votes map[byte]int
}
var rows []Group
func ParseFile(input string) {
row := Group{
Size: 0,
Votes: make(map[byte]int),
}
// Parse file
for _, line := range utils.GetLinesFromFile("day06/" + input + ".txt") {
// Commit group to list on group change
if line == "" {
rows = append(rows, row)
row = Group{
Size: 0,
Votes: make(map[byte]int),
}
continue
}
// Increment group size
row.Size++
// Go through votes
for i := 0; i < len(line); i++ {
// Increment vote count
row.Votes[line[i]]++
}
}
// Don't drop last entry
rows = append(rows, row)
}