0
\$\begingroup\$

I was unsure if this type of question was on topic here so I decided to post on meta first instead of just trying it "in the wild".

A 52 card deck is shuffled and cut in half. The top half is set aside. What is the fastest way to determine how many sets of cards total 21 in the remaining half? Cards cannot be re-used.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ FWIW, the answer to "What is the fastest way?" is often "A lookup table", and that applies here. \$\endgroup\$ – Peter Taylor Jul 11 '14 at 9:48
  • \$\begingroup\$ @PeterTaylor There are 52!/(26! * 26!) possible half decks (I think). Can you store the lookup table? \$\endgroup\$ – dmckee --- ex-moderator kitten Jul 11 '14 at 18:34
  • \$\begingroup\$ @dmckee, suits are irrelevant, so the lookup table has on the order of 2^30 entries. Large, but I've worked with data sets that size. \$\endgroup\$ – Peter Taylor Jul 11 '14 at 19:29
  • \$\begingroup\$ Ah ... yes. I hadn't noticed that. So it's manageable. \$\endgroup\$ – dmckee --- ex-moderator kitten Jul 11 '14 at 19:30
4
\$\begingroup\$

The question

What is the quickest way to determine the maximum number of sets of cards totally 21 that can be formed from a random half of a deck of cards?

is not formed as a challenge for other programmers to compete on. That means it is off-topic.

However, you should certainly be able to write a challenge from it.

The simplest possibility would be a , but a where you time the operation of various contestants on a random set of N draws (with wait4 or the equivalent on non-unix platforms) is another option.

Posing it as a won't get you screaming fast solutions, but will probably yield some surprising ones.

In any case, to make it a challenge, carefully and unambiguously specify what the entry should do (and if it should be a program or a program fragment) and tell us how entries will be judged.


1 In fact, that suggests one possible a way to formalize , which has never had a really precise definition.

| |
\$\endgroup\$
  • \$\begingroup\$ Although if it is written as a fastest-code, it needs rewriting to be parameterisable, because as is it will probably be soluble in less time than can accurately be measured. \$\endgroup\$ – Peter Taylor Jul 11 '14 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .