From 827835f12f9d453767b2f56710f3c0a006dfab48 Mon Sep 17 00:00:00 2001 From: xuu Date: Thu, 7 Dec 2023 19:29:34 -0700 Subject: [PATCH 1/2] fix: forgot to add wild card --- day07/main.go | 1 + day07/main_test.go | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/day07/main.go b/day07/main.go index 309b21f..222b491 100644 --- a/day07/main.go +++ b/day07/main.go @@ -44,6 +44,7 @@ func run(scan *bufio.Scanner) (uint64, uint64) { product1 := calcProduct(game) game.cardOrder = getOrder(2) + game.wildCard = 'J' product2 := calcProduct(game) return product1, product2 diff --git a/day07/main_test.go b/day07/main_test.go index f4226b1..2dccf17 100644 --- a/day07/main_test.go +++ b/day07/main_test.go @@ -40,7 +40,6 @@ func TestHands(t *testing.T) { h = Play{0, []rune("QQQJA"), &game} is.Equal(h.HandType(), "3K-Q") is.Equal(fmt.Sprintf("%x", h.HandStrength()), "4bbbad") - } func TestPower(t *testing.T) { @@ -69,5 +68,5 @@ func TestSolution(t *testing.T) { is.Equal(score1, uint64(248559379)) t.Log("score2", score2) - is.Equal(score2, uint64(248761814)) + is.Equal(score2, uint64(249631254)) } From e6c53df5c5e6174a7452c158dadf0da540e93876 Mon Sep 17 00:00:00 2001 From: xuu Date: Thu, 7 Dec 2023 20:09:58 -0700 Subject: [PATCH 2/2] chore: cleanup --- day07/main.go | 14 +++++--------- day07/main_test.go | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/day07/main.go b/day07/main.go index 222b491..f3d3697 100644 --- a/day07/main.go +++ b/day07/main.go @@ -9,7 +9,7 @@ import ( func main() { if len(os.Args) != 2 { - fmt.Fprintln(os.Stderr, "Usage: day06 FILE") + fmt.Fprintln(os.Stderr, "Usage: day07 FILE") } input, err := os.Open(os.Args[1]) @@ -40,10 +40,10 @@ func run(scan *bufio.Scanner) (uint64, uint64) { game.plays = append(game.plays, Play{bid, []rune(cards), &game}) } - game.cardOrder = getOrder(1) + game.cardOrder = getOrder(cardTypes1) product1 := calcProduct(game) - game.cardOrder = getOrder(2) + game.cardOrder = getOrder(cardTypes2) game.wildCard = 'J' product2 := calcProduct(game) @@ -65,11 +65,7 @@ func calcProduct(game Game) uint64 { return product } -func getOrder(v int) map[rune]int { - cardTypes := cardTypes1 - if v == 2 { - cardTypes = cardTypes2 - } +func getOrder(cardTypes []rune) map[rune]int { cardOrder := make(map[rune]int, len(cardTypes)) for i, r := range cardTypes { cardOrder[r] = len(cardTypes) - i @@ -228,7 +224,7 @@ func (g *Game) Counts(cards []rune) map[rune]int { } return m } -func (g *Game)hasSame(cards []rune) (has1, has2, has3, has4, has5 bool) { +func (g *Game) hasSame(cards []rune) (has1, has2, has3, has4, has5 bool) { cnt := g.Counts(cards) for _, c := range cnt { switch c { diff --git a/day07/main_test.go b/day07/main_test.go index 2dccf17..19f84ee 100644 --- a/day07/main_test.go +++ b/day07/main_test.go @@ -24,7 +24,7 @@ func TestHands(t *testing.T) { is := is.New(t) var game Game - game.cardOrder = getOrder(1) + game.cardOrder = getOrder(cardTypes1) h := Play{0, []rune("AAA23"), &game} is.Equal(h.HandType(), "3K-A")