Skip to content

Commit d2eecb7

Browse files
committed
Advent of Code (Go): add ParseCharCoords()
1 parent f7b8f2d commit d2eecb7

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

advent_of_code.go/helpers/parsers.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package helpers
22

3-
import "strings"
3+
import (
4+
"strings"
5+
sets "github.com/deckarep/golang-set/v2"
6+
)
47

58
func ParseOneNumber(data string) int {
69
return Atoi(data)
@@ -46,3 +49,16 @@ func ParseMultiWordsPerLine(data string) [][]string {
4649
}
4750
return words
4851
}
52+
53+
func ParseCharCoords(data string) map[rune]sets.Set[[2]int] {
54+
c := make(map[rune]sets.Set[[2]int])
55+
for y, line := range strings.Split(data, "\n") {
56+
for x, char := range line {
57+
if _, ok := c[char]; !ok {
58+
c[char] = sets.NewSet[[2]int]()
59+
}
60+
c[char].Add([2]int{x, y})
61+
}
62+
}
63+
return c
64+
}

0 commit comments

Comments
 (0)