diff --git a/2023/day07_camel_cards.go b/2023/day07_camel_cards.go index 49a7517..8245661 100644 --- a/2023/day07_camel_cards.go +++ b/2023/day07_camel_cards.go @@ -36,14 +36,6 @@ func newD07Hand(hand string, bid int) d07Hand { } } -func newD07HandP2(hand string, bid int) d07Hand { - return d07Hand{ - hand: hand, - bid: bid, - value: d07HandValueP2(hand), - } -} - func Day07Part1(input io.Reader) (int, error) { scanner := bufio.NewScanner(input) @@ -153,11 +145,19 @@ func Day07Part2(input io.Reader) (int, error) { return sum, nil } +func newD07HandP2(hand string, bid int) d07Hand { + return d07Hand{ + hand: hand, + bid: bid, + value: d07HandValueP2(hand), + } +} + func d07HandValueP2(hand string) int { count := make(map[rune]byte) - var maxCount byte = 1 + var maxCount byte = 0 var maxFor rune - var secondMax byte = 1 + var secondMax byte = 0 for _, c := range hand { v := count[c] v++ diff --git a/2023/day07_camel_cards_test.go b/2023/day07_camel_cards_test.go index 60972c8..9d99b6c 100644 --- a/2023/day07_camel_cards_test.go +++ b/2023/day07_camel_cards_test.go @@ -22,7 +22,7 @@ func TestDay07Part2(t *testing.T) { tests := []testCase{ {"inputs/day07_test1", 5905}, {"inputs/day07_test2", 5911}, - {"inputs/day07", 0}, // 247974245 is too low + {"inputs/day07", 248256639}, } for _, test := range tests { t.Run(test.filename, check(test, Day07Part2)) @@ -64,6 +64,7 @@ func TestDay07HandValueP2(t *testing.T) { hand string expected int }{ + {"JJJJJ", d07HandFive}, {"AAAAA", d07HandFive}, {"AAJJJ", d07HandFive}, {"AAAA2", d07HandFour}, @@ -157,6 +158,14 @@ func TestD07CmpHandsP2(t *testing.T) { args: args{"QQQQ2", "JKKK2"}, want: 1, }, + { + args: args{"QQQQ2", "JJJJJ"}, + want: -1, + }, + { + args: args{"22222", "JJJJJ"}, + want: 1, + }, } for _, tt := range tests { char := "<"