4
\$\begingroup\$

Represent poker cards as numbers from 0 to 51. 0 to 12 - all hearts from 2 to Ace, 13 to 25 all diamonds and so on. Your goal is to write a function for each poker hand type which generates a random 7-card hand (as in Texas Holdem on the river), in which the best 5-card combination is of the target type. The output is a sequence of 7 numbers. So, your function accepts a number from 0 to 8, where 0 is a High Card poker hand type and 8 is a Straight Flush, and returns a sequence of 7 numbers which represent the hand.

Additional requirements:

  1. The hand should be sampled uniformly from all the possible hands of the given type. For example, it's not ok to generate straight flushes which always end with Ace.

  2. You can't use or generate any look up tables bigger then 1000 values. For example, it's not ok to generate all flushes and than select a random one from them.

  3. Generating completely random sets of 7 cards and checking for the target type until it is found is not allowed. Basically your function should have defined upper time limit.

\$\endgroup\$
10
  • \$\begingroup\$ What's the (objective) winning criterion? \$\endgroup\$ Jun 22, 2014 at 9:31
  • \$\begingroup\$ @m.buettner added tag for popularity contest. Basically I solved this problem straightforwardly on scala myself, but code is too big and ugly to be proud of and I can't find nice and clear algorithm, which I believe exists. \$\endgroup\$
    – GrayR
    Jun 22, 2014 at 9:38
  • 6
    \$\begingroup\$ If you're looking for a nice and clear algorithm codegolf.SE is not the right place to ask for it, regardless of the winning criterion. You might want to try codereview.SE instead. As for your challenge, I think it could be interesting as a plain code golf challenge (shortest code wins). \$\endgroup\$ Jun 22, 2014 at 9:44
  • 4
    \$\begingroup\$ I'm not sure why already having a working algorithm prevents you from posting it on codereview.SE. In fact, that's exactly what CR is for - you've got a solution, but you don't think it's optimal, so you want others to have a look at it and see if they can improve it. Anyway, retracting my close vote. As code golf it sounds like good fun. \$\endgroup\$ Jun 22, 2014 at 9:51
  • 2
    \$\begingroup\$ The new rule 3 forbids the most obvius solution. Now, what about generating a random set then 'count up' until the target type is found? \$\endgroup\$
    – edc65
    Jun 22, 2014 at 13:35

0

Browse other questions tagged or ask your own question.