mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-12-21 21:31:53 +01:00
solve day 7 part 2
This commit is contained in:
parent
17049c1f98
commit
090495d0e9
2 changed files with 20 additions and 11 deletions
|
@ -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++
|
||||
|
|
|
@ -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 := "<"
|
||||
|
|
Loading…
Reference in a new issue