2020 Day 6 Complete

This commit is contained in:
Brian Buller 2020-12-06 10:31:50 -06:00
parent d75d444470
commit 02a61cefbe
3 changed files with 2337 additions and 0 deletions

2248
2020/day06/input Executable file

File diff suppressed because it is too large Load Diff

74
2020/day06/main.go Normal file
View File

@ -0,0 +1,74 @@
package main
import (
"bytes"
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
fmt.Println("# Day 6")
inp := h.StdinToStringSlice()
part2(inp)
}
func part1(inp []string) {
yeses := make(map[byte]bool)
var total int
for _, v := range inp {
if v == "" {
fmt.Printf("Group Total: %d\n", len(yeses))
total = total + len(yeses)
yeses = make(map[byte]bool)
} else {
for _, i := range v {
yeses[byte(i)] = true
}
}
}
fmt.Printf("Group Total: %d\n", len(yeses))
total = total + len(yeses)
fmt.Printf("Answer: %d\n", total)
}
func part2(inp []string) {
var total int
yeses := []byte{}
newgroup := true
for _, v := range inp {
if v == "" {
newgroup = true
var grouptotal int
for yk := range yeses {
if yeses[yk] != ' ' {
grouptotal++
}
}
total = total + grouptotal
fmt.Printf("Totals: %d -> %d\n", grouptotal, total)
} else {
if newgroup {
newgroup = false
yeses = []byte(v)
fmt.Println("Initializing", string(yeses))
} else {
for yk, yv := range yeses {
if !bytes.Contains([]byte(v), []byte{yv}) {
yeses[yk] = ' '
fmt.Println("Removing", string(yv), "->", string(yeses))
}
}
}
}
}
var grouptotal int
for yk := range yeses {
if yeses[yk] != ' ' {
grouptotal++
}
}
total = total + grouptotal
fmt.Printf("Totals: %d -> %d\n", grouptotal, total)
fmt.Printf("Answer: %d\n", total)
}

15
2020/day06/testinput Normal file
View File

@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b