add second answer

This commit is contained in:
Nico 2020-12-06 13:08:45 +00:00
parent 7831e58928
commit 777fa8e9d6
1 changed files with 36 additions and 0 deletions

36
day6/main2.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"io/ioutil"
"fmt"
"strings"
)
func main() {
d, _ := ioutil.ReadFile("input")
s := string(d)
//s := "abc\n\na\nb\nc\n\nab\nac\n\na\na\na\na\n\nb\n"
groups := strings.Split(strings.Trim(s,"\n"),"\n\n")
total := 0
for _, g := range groups {
results := make(map[rune]int)
lines := strings.Split(g,"\n")
for _, l := range lines {
for _, c := range l {
if _, ok := results[c]; !ok { // if it's not already there
results[c] = 1
} else {
results[c] += 1
}
}
}
for q, c := range results {
if c != len(lines) {
delete(results, q)
}
}
fmt.Println(results)
total += len(results)
}
fmt.Println(total)
}