day07

package
v0.0.0-...-cede9f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicCardStrengthDeterminer

func BasicCardStrengthDeterminer(r rune) int

Determines the card strength based on the order of the given card, AKQJT98765432.

func SortRanksByStrength

func SortRanksByStrength(a, b Rank) int

This function defines how to sort a list of ranks by its strength

func WildcardCardStrengthDeterminer

func WildcardCardStrengthDeterminer(r rune) int

Determines the strength of the card exactly like in BasicCardStrengthDeterminer but moving 'J' to the bottom

Types

type Card

type Card struct {
	// contains filtered or unexported fields
}

Type representing a Card in the Camel Cards game the valid values are: A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, or 2

func NewCard

func NewCard(
	c rune,
	strengthDeterminer func(rune) int,
) (Card, error)

Card constructor. It validates the rune is valid. If not, it will return an error.

func (Card) GoString

func (c Card) GoString() string

GoString implementation

func (Card) Strength

func (c Card) Strength() int

Strength of the card

func (Card) String

func (c Card) String() string

String representation of a Card

type Exercise

type Exercise struct{}

func (Exercise) Part1

func (e Exercise) Part1(data string) (int, error)

func (Exercise) Part2

func (e Exercise) Part2(data string) (int, error)

type Hand

type Hand struct {
	HandType HandType
	// contains filtered or unexported fields
}

Represents a hand in the Camel Cards game

func NewHand

func NewHand(
	cards string,
	handTypeDeterminer func([5]Card) HandType,
	cardStrengthDeterminer func(rune) int,
) (Hand, error)

Hand constructor from a string, like "32T3K" If something goes wrong while parsing the Cards the error is returned

func (Hand) String

func (h Hand) String() string

type HandType

type HandType int

Represents the Hand type, based on the given cards

const (
	HighCard HandType = iota
	OnePair
	TwoPair
	ThreeOfKind
	FullHouse
	FourOfKind
	FiveOfKind
)

Ordered from less to more value

func BasicHandDeterminer

func BasicHandDeterminer(cards [5]Card) HandType

Calculates which HandType should be used of a given set of cards. It does not return any error, as it does not check that the cards are valid.

func WildcardHandDeterminer

func WildcardHandDeterminer(cards [5]Card) HandType

The function takes into account that 'J' are comodin cards, and therefore, can count towards other types

func (HandType) String

func (h HandType) String() string

String representation of HandType

type Rank

type Rank struct {
	Hand
	Bid int
}

Represents a Rank, aka, a hand in the Camel Cards with its corresponding bid.

func NewRank

func NewRank(hand Hand, bid int) Rank

Generates a new rank, with score equal to zero

func Parse

func Parse(
	data string,
	handDeterminer func([5]Card) HandType,
	cardStrengthDeterminer func(rune) int,
) ([]Rank, error)

Parses the given text as a list of hands

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL