43 lines
713 B
Go
43 lines
713 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"internal/util"
|
|
)
|
|
|
|
func main() {
|
|
lines := util.ReadInput()
|
|
|
|
twos := 0
|
|
threes := 0
|
|
for _, id := range lines {
|
|
// here we build up a map of letters and counts
|
|
letters := make(map[byte]int)
|
|
for i := 0; i < len(id); i++ {
|
|
letters[id[i]] += 1
|
|
}
|
|
|
|
// these are the values to add to the 'twos' and 'threes'
|
|
// count, respectively. They will only ever be 0 or 1.
|
|
add2 := 0
|
|
add3 := 0
|
|
|
|
// now we iterate over the map of letter->count, and set
|
|
// add2 and add3 if we find any values equal to 2 or 3
|
|
for _, v := range letters {
|
|
if v == 2 {
|
|
add2 = 1
|
|
}
|
|
if v == 3 {
|
|
add3 = 1
|
|
}
|
|
}
|
|
|
|
twos += add2
|
|
threes += add3
|
|
}
|
|
|
|
fmt.Println(twos * threes)
|
|
}
|