Laurent Le Brun - Poker: a programming problem - Comments2023-10-09T17:38:46+01:00urn:md5:e38112cdb33db872783d35c137672e1dDotclearPoker: a programming problem - Laurent Le Brunurn:md5:826fa8cf4b1eb6c5c65c286a9b5c225a2008-10-12T12:02:42+00:002008-10-12T12:02:42+00:00Laurent Le Brun<p>Thanks! You're right. :)</p>Poker: a programming problem - Keith Dahlbyurn:md5:5058c64c576292b8a76ce79d2316389a2008-10-12T02:40:13+00:002008-10-12T02:40:13+00:00Keith Dahlby<p>Also found a border case on the off chance the player has two sets of three:<br />
| (n, 3) :: (n2, 2) :: _ -> FullHouse (n, n2)<br />
<br />
Should be something like:<br />
| (n, 3) :: (n2, c) :: _ when c >= 2 -> FullHouse (n, n2)</p>Poker: a programming problem - Keith Dahlbyurn:md5:3bafe002346c74bb093cd0f681a7d73d2008-10-12T02:13:22+00:002008-10-12T02:13:22+00:00Keith Dahlby<p>Very nicely done! One case you didn't handle is an Ace-low straight, which might be handled as follows:<br />
<br />
let test_sequence =<br />
let append_ace h =<br />
match Seq.tryfind (fun s -> s = 14) h with<br />
| Some _ -> Seq.append h [|1|]<br />
| None -> h<br />
Seq.map value<br />
>> Seq.distinct<br />
>> append_ace<br />
>> Seq.sort_by (~-)<br />
>> Seq.windowed 5<br />
>> Seq.tryfind (fun s -> s = [|s.[0] .. -1 .. s.[0]-4|])<br />
<br />
And a test hand:<br />
play ["Ah 2h 4h 5d 6c 3h 5h"]<br />
<br />
There's probably a more elegant way to handle it, but that's what came to mind.<br />
<br />
Cheers ~<br />
Keith</p>Poker: a programming problem - Brianurn:md5:83e535f6bc028f9964c2d224fa311ab02008-10-05T22:11:59+00:002008-10-05T22:11:59+00:00Brian<p>Nice! You are pre-empting and besting some of my own ideas, so I may have to steal from you in future blog entries. :)</p>