day7: Explain theory a bit
This commit is contained in:
parent
5674535478
commit
ceaf7c8735
12
day7/day7.kt
12
day7/day7.kt
|
@ -87,6 +87,18 @@ fun typeJoker(cards: Hand): Int {
|
||||||
}
|
}
|
||||||
|
|
||||||
val jokers = groups.remove('J') ?: 0
|
val jokers = groups.remove('J') ?: 0
|
||||||
|
|
||||||
|
// Jokers act as a kind of tie breaker here - similar to the full
|
||||||
|
// scenario, the label we want to add the joker to is the one with
|
||||||
|
// the highest card value *as well as* the highest type.
|
||||||
|
//
|
||||||
|
// So we sort it first by value (descending so the highest type
|
||||||
|
// gets i == 0), and second by the value of the card (so that if
|
||||||
|
// two hands have the same type the one with the higher card value
|
||||||
|
// wins).
|
||||||
|
//
|
||||||
|
// The hands are base 13 numbers, so multiplying the value puts it
|
||||||
|
// one digit ahead of the card value.
|
||||||
return groups.entries.sortedByDescending { 13 * it.value + cardValueJoker(it.key) }.foldIndexed(
|
return groups.entries.sortedByDescending { 13 * it.value + cardValueJoker(it.key) }.foldIndexed(
|
||||||
0
|
0
|
||||||
) { i, acc, entry ->
|
) { i, acc, entry ->
|
||||||
|
|
Loading…
Reference in a new issue