Last active
January 31, 2021 14:55
-
-
Save ohbarye/0e115b698dd1760765e47950bda7f92a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/ioutil" | |
"strings" | |
) | |
func main() { | |
bytes, _ := ioutil.ReadFile("./input.txt") | |
input := strings.TrimRight(string(bytes), "\n") | |
sum := 0 | |
for _, group := range strings.Split(input, "\n\n") { | |
m := make(map[rune]bool) | |
for _, row := range strings.Fields(group) { | |
for _, c := range row { | |
m[c] = true | |
} | |
} | |
sum += len(m) | |
} | |
println(sum) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/ioutil" | |
"strings" | |
) | |
func main() { | |
bytes, _ := ioutil.ReadFile("./input.txt") | |
input := strings.TrimRight(string(bytes), "\n") | |
sum := 0 | |
for _, group := range strings.Split(input, "\n\n") { | |
m := make(map[rune]int) | |
groupCount := 0 | |
for _, row := range strings.Fields(group) { | |
for _, c := range row { | |
if val, ok := m[c]; ok { | |
m[c] = val + 1 | |
} else { | |
m[c] = 1 | |
} | |
} | |
groupCount++ | |
} | |
for _, element := range m { | |
if element == groupCount { | |
sum++ | |
} | |
} | |
} | |
println(sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment