day 7 more cleanup
we don't need to know the card identities when determining hand-type, just the countsmain
parent
8081b6f1fa
commit
ba438b7b05
|
@ -40,26 +40,27 @@ proc type hand {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
array set n {}
|
array set n {}
|
||||||
set j 0
|
set jokers 0
|
||||||
foreach c [split $hand ""] {
|
foreach c [split $hand ""] {
|
||||||
if {$c ne "X"} {
|
if {$c ne "X"} {
|
||||||
incr n($c)
|
incr n($c)
|
||||||
} else {
|
} else {
|
||||||
incr j
|
incr jokers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set groups [lsort -decreasing -stride 2 -index 1 -integer [array get n]]
|
set counts [lmap {k v} [array get n] {list $v}]
|
||||||
|
set counts [lsort -decreasing -integer $counts]
|
||||||
# more of the same card is always better,
|
# more of the same card is always better,
|
||||||
# so add the jokers to the most frequent card
|
# so add the jokers to the most frequent card
|
||||||
lset groups 1 [expr {$j + [lindex $groups 1]}]
|
lset counts 0 [expr {$jokers + [lindex $counts 0]}]
|
||||||
#puts $groups
|
#puts $groups
|
||||||
return [switch -glob $groups {
|
return [switch -glob $counts {
|
||||||
{? 5} {{#} Five of a kind; list 1}
|
{5} {{#} Five of a kind; list 1}
|
||||||
{? 4 *} {{#} Four of a kind; list 2}
|
{4 *} {{#} Four of a kind; list 2}
|
||||||
{? 3 ? 2} {{#} Full house; list 3}
|
{3 2} {{#} Full house; list 3}
|
||||||
{? 3 *} {{#} Three of a kind; list 4}
|
{3 *} {{#} Three of a kind; list 4}
|
||||||
{? 2 ? 2 *} {{#} Two pair; list 5}
|
{2 2 *} {{#} Two pair; list 5}
|
||||||
{? 2 *} {{#} One pair; list 6}
|
{2 *} {{#} One pair; list 6}
|
||||||
default {list 7}
|
default {list 7}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue