Compare commits

..

No commits in common. "fb09a45caba05cfb1569862cbdfd831c722d4342" and "5ec77ca0f81963eead8e0596480cd817c35d1094" have entirely different histories.

2 changed files with 12 additions and 8 deletions

View File

@ -9,7 +9,7 @@ import (
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: day07 FILE")
fmt.Fprintln(os.Stderr, "Usage: day06 FILE")
}
input, err := os.Open(os.Args[1])
@ -40,11 +40,10 @@ func run(scan *bufio.Scanner) (uint64, uint64) {
game.plays = append(game.plays, Play{bid, []rune(cards), &game})
}
game.cardOrder = getOrder(cardTypes1)
game.cardOrder = getOrder(1)
product1 := calcProduct(game)
game.cardOrder = getOrder(cardTypes2)
game.wildCard = 'J'
game.cardOrder = getOrder(2)
product2 := calcProduct(game)
return product1, product2
@ -65,7 +64,11 @@ func calcProduct(game Game) uint64 {
return product
}
func getOrder(cardTypes []rune) map[rune]int {
func getOrder(v int) map[rune]int {
cardTypes := cardTypes1
if v == 2 {
cardTypes = cardTypes2
}
cardOrder := make(map[rune]int, len(cardTypes))
for i, r := range cardTypes {
cardOrder[r] = len(cardTypes) - i
@ -224,7 +227,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 {

View File

@ -24,7 +24,7 @@ func TestHands(t *testing.T) {
is := is.New(t)
var game Game
game.cardOrder = getOrder(cardTypes1)
game.cardOrder = getOrder(1)
h := Play{0, []rune("AAA23"), &game}
is.Equal(h.HandType(), "3K-A")
@ -40,6 +40,7 @@ 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) {
@ -68,5 +69,5 @@ func TestSolution(t *testing.T) {
is.Equal(score1, uint64(248559379))
t.Log("score2", score2)
is.Equal(score2, uint64(249631254))
is.Equal(score2, uint64(248761814))
}