chore: clean up day 3
This commit is contained in:
@@ -2,14 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//go:embed input.txt
|
||||
var input []byte
|
||||
aoc "go.sour.is/advent-of-code-2023"
|
||||
)
|
||||
|
||||
type partNumber struct {
|
||||
number int
|
||||
@@ -56,10 +54,14 @@ func (tab symbolTab) scanSymbol(p partNumber) bool {
|
||||
// 553079
|
||||
// 84363105
|
||||
|
||||
func main() {
|
||||
buf := bytes.NewReader(input)
|
||||
scan := bufio.NewScanner(buf)
|
||||
func main() { aoc.MustResult(aoc.Runner(run)) }
|
||||
|
||||
type result struct {
|
||||
valuePT1 int
|
||||
valuePT2 int
|
||||
}
|
||||
|
||||
func run(scan *bufio.Scanner) (*result, error) {
|
||||
parts := []partNumber{}
|
||||
symbols := make(symbolTab)
|
||||
symbolList := []*symbol{}
|
||||
@@ -95,6 +97,7 @@ func main() {
|
||||
if v, err := strconv.Atoi(string(slice)); err == nil {
|
||||
parts = append(parts, partNumber{number: v, row: row, col: col - len(slice), end: col - 1})
|
||||
slice = slice[:0]
|
||||
_ = slice
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +122,5 @@ func main() {
|
||||
// fmt.Println(symbolList)
|
||||
fmt.Println("part1:", sum)
|
||||
fmt.Println("part2:", sumGears)
|
||||
return &result{sum, sumGears}, nil
|
||||
}
|
||||
|
||||
43
day03/main_test.go
Normal file
43
day03/main_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"testing"
|
||||
|
||||
"github.com/matryer/is"
|
||||
)
|
||||
|
||||
//go:embed example.txt
|
||||
var example []byte
|
||||
|
||||
//go:embed input.txt
|
||||
var input []byte
|
||||
|
||||
func TestExample(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(example))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result)
|
||||
is.Equal(result.valuePT1, int(4361))
|
||||
|
||||
is.Equal(result.valuePT2, 467835)
|
||||
}
|
||||
|
||||
func TestInput(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(input))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result.valuePT1)
|
||||
is.Equal(result.valuePT1, int(553079))
|
||||
|
||||
t.Log(result.valuePT2)
|
||||
is.Equal(result.valuePT2, 84363105)
|
||||
}
|
||||
Reference in New Issue
Block a user