chore: imporivements
Some checks failed
Go Bump / bump (push) Successful in 6s
Go Test / build (push) Failing after 29s

This commit is contained in:
xuu
2023-12-13 08:32:37 -07:00
parent 127e9c33c6
commit 927fabebfc
9 changed files with 145 additions and 138 deletions

View File

@@ -3,29 +3,19 @@ package main
import (
"bufio"
"fmt"
"os"
"sort"
aoc "go.sour.is/advent-of-code-2023"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: day07 FILE")
}
func main() { aoc.MustResult(aoc.Runner(run)) }
input, err := os.Open(os.Args[1])
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
scan := bufio.NewScanner(input)
score1, score2 := run(scan)
fmt.Println("score 1", score1)
fmt.Println("score 2", score2)
type result struct {
valuePT1 uint64
valuePT2 uint64
}
func run(scan *bufio.Scanner) (uint64, uint64) {
func run(scan *bufio.Scanner) (result, error) {
var game Game
for scan.Scan() {
@@ -47,7 +37,7 @@ func run(scan *bufio.Scanner) (uint64, uint64) {
game.wildCard = 'J'
product2 := calcProduct(game)
return product1, product2
return result{product1, product2}, nil
}
var cardTypes1 = []rune{'A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2'}

View File

@@ -54,19 +54,21 @@ func TestExample(t *testing.T) {
is := is.New(t)
scan := bufio.NewScanner(bytes.NewReader(example))
score1, score2 := run(scan)
is.Equal(score1, uint64(6440))
is.Equal(score2, uint64(5905))
r, err := run(scan)
is.NoErr(err)
is.Equal(r.valuePT1, uint64(6440))
is.Equal(r.valuePT2, uint64(5905))
}
func TestSolution(t *testing.T) {
is := is.New(t)
scan := bufio.NewScanner(bytes.NewReader(input))
score1, score2 := run(scan)
t.Log("score1", score1)
is.Equal(score1, uint64(248559379))
r, err := run(scan)
is.NoErr(err)
t.Log("score1", r.valuePT1)
is.Equal(r.valuePT1, uint64(248559379))
t.Log("score2", score2)
is.Equal(score2, uint64(249631254))
t.Log("score2", r.valuePT2)
is.Equal(r.valuePT2, uint64(249631254))
}