Browse Source

2020 Day 6 Complete

master
Brian Buller 11 months ago
parent
commit
02a61cefbe
  1. 2248
      2020/day06/input
  2. 74
      2020/day06/main.go
  3. 15
      2020/day06/testinput

2248
2020/day06/input

File diff suppressed because it is too large

74
2020/day06/main.go

@ -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

@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b
Loading…
Cancel
Save