summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-12-21 14:41:32 +0100
committerMartin Polden <mpolden@mpolden.no>2023-12-21 14:41:32 +0100
commitda3522352cd48597453507a4171b90a43c30f63b (patch)
tree88163640fdeb510ab24fbfb12fcc365821f68528
parent27b990f30b993c06ff9db5e4d6a2b7e35575c3b6 (diff)
aoc23: requireInt -> atoi
-rw-r--r--aoc23/day01_test.go2
-rw-r--r--aoc23/day02_test.go4
-rw-r--r--aoc23/day03_test.go2
-rw-r--r--aoc23/day04_test.go4
-rw-r--r--aoc23/util.go2
5 files changed, 7 insertions, 7 deletions
diff --git a/aoc23/day01_test.go b/aoc23/day01_test.go
index 21f66ba..4ab3ee2 100644
--- a/aoc23/day01_test.go
+++ b/aoc23/day01_test.go
@@ -11,7 +11,7 @@ func findDigits(text string, parseWords bool) []int {
buf := ""
for _, c := range text {
if isDigit(c) {
- n := requireInt(string(c))
+ n := atoi(string(c))
ints = append(ints, n)
} else if parseWords {
buf += string(c)
diff --git a/aoc23/day02_test.go b/aoc23/day02_test.go
index b34615c..143ec97 100644
--- a/aoc23/day02_test.go
+++ b/aoc23/day02_test.go
@@ -15,13 +15,13 @@ type Rgb struct{ r, g, b int }
func parseGame(line string) Game {
parts := strings.Split(line, ": ")
- id := requireInt(parts[0][5:])
+ id := atoi(parts[0][5:])
var cubes []Rgb
for _, p := range strings.Split(parts[1], "; ") {
c := Rgb{}
for _, p2 := range strings.Split(p, ", ") {
parts := strings.Split(p2, " ")
- count := requireInt(parts[0])
+ count := atoi(parts[0])
color := parts[1]
switch color {
case "red":
diff --git a/aoc23/day03_test.go b/aoc23/day03_test.go
index 6ce0758..56bd252 100644
--- a/aoc23/day03_test.go
+++ b/aoc23/day03_test.go
@@ -72,7 +72,7 @@ func findNumber(r io.Reader, consumer func(int, []Point, [][]rune)) {
parsingNumber = false
}
if !parsingNumber && number != "" {
- consumer(requireInt(number), points.Slice(), grid)
+ consumer(atoi(number), points.Slice(), grid)
points.Reset()
number = ""
}
diff --git a/aoc23/day04_test.go b/aoc23/day04_test.go
index c5655dd..6fd5c34 100644
--- a/aoc23/day04_test.go
+++ b/aoc23/day04_test.go
@@ -15,9 +15,9 @@ type Card struct {
func parseCard(s string) Card {
parts := strings.FieldsFunc(s, func(r rune) bool { return r == ':' || r == '|' })
- winning := transform(strings.Fields(parts[1]), requireInt)
+ winning := transform(strings.Fields(parts[1]), atoi)
slices.Sort(winning)
- numbers := transform(strings.Fields(parts[2]), requireInt)
+ numbers := transform(strings.Fields(parts[2]), atoi)
return Card{winning, numbers, -1}
}
diff --git a/aoc23/util.go b/aoc23/util.go
index 269a98a..1a0ba5b 100644
--- a/aoc23/util.go
+++ b/aoc23/util.go
@@ -50,7 +50,7 @@ func parseLines[T any](r io.Reader, parser func(line string) T) []T {
return values
}
-func requireInt(s string) int {
+func atoi(s string) int {
n, err := strconv.Atoi(s)
if err != nil {
panic(err)