Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 126649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:21:04+00:00 2026-05-11T05:21:04+00:00

I’m developing a card game that uses rummy-style sets of three cards. From a

  • 0

I’m developing a card game that uses rummy-style sets of three cards. From a random selection of cards, I need the algorithm to pick out which cards would get me the highest number of sets.

By ‘rummy-style sets of three’ I mean:

  • All three cards have the same value, like three Jacks. OR
  • All three cards are of the same suit and sequential in order, like a 7, 8, 9 all of diamonds.

For example, given the cards: 6D, 7D, 7C, 7H, 8D, 8C, 9C, 10H
I could form the set: {7D, 7C, 7H}, but that would be the only set I would get out of it, and it would not be optimum.
The optimum sets in this case are: { {6D, 7D, 8D}, {7C, 8C, 9C} }

I have tried brute force (permute through all the given cards, see what matches in order in that permutation), but that proved too slow. The problem feels like it has similarities to other solved problems, and that’s why I ask here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:21:05+00:00Added an answer on May 11, 2026 at 5:21 am

    if you have N cards (N = 8), you can enumerate through all the distinct triples in the set in time N * (N – 1) * (N – 2) (with N = 8 you get 336). This is pretty fast. Check which ones of the triples are ‘rummy-style’ sets, and store them in a table as integer triples (the integer denote the sequence numbers of the cards).

    That’s the first step. The second step is now to do combinatorial optimization and calculate the optimal choice. The simple way to do this is to use backtracking search. You run an index (‘i’) over the set of triples you have found. First you try to include the ‘i’th triple in the solution, and then continue from index i+1 recursively; then you backtrack and decide that the ‘i’th triple is not in the solution, and continue from i+1 recursively. There are many optimizations to this, but for the small sets it’s going to work pretty fine.

    Here how it works with your example:

    Cards: 6D, 7D, 7C, 7H, 8D, 8C, 9C, 10H

    Let’s enumerate all the possible triples:

    Cards        Index triple 6D 7D 8D     <0, 1, 4> 7D 7C 7H     <1, 2, 3> 7C 8C 9C     <2, 5, 6> 

    The full backtracking search goes like this:

    Decide on <0, 1, 4>:   <0, 1, 4> INCLUDED:      <1, 2, 3> CLASHES with <0, 1, 4>      Decide on <2, 5, 6>:        <2, 5, 6> INCLUDED:           Solution with 2 sets (* BEST SOLUTION)        <2, 5, 6> EXCLUDED:           Solution with 1 sets   <0, 1, 4> EXCLUDED:      Decide on <1, 2, 3>:         <1, 2, 3> INCLUDED:            <2, 5, 6> CLASHES with <1, 2, 3>            Solution with 1 sets         <1, 2, 3> EXCLUDED:            Decide on <2, 5, 6>:              <2, 5, 6> INCLUDED:                 Solution with 1 set              <2, 5, 6> EXCLUDED:                 Solution with 0 sets 

    Then you pick the solution with most sets (marked with asterisk).

    This is pretty simple to implement. Try it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.