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 9181167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:13:22+00:00 2026-06-17T18:13:22+00:00

I am trying to build an algorithm which chooses a combination of 4 horses

  • 0

I am trying to build an algorithm which chooses a combination of 4 horses from a number of races.

So say we have 10 races, each with 8 horses running: I want all combinations of 4 horses from these races, with the condition that the 4 horses have to come from separate races (no two horses in the same combination can come from the same race).

Is there a name for this problem (and existing algorithm)?

I assume it’ll just be a series of loops but I haven’t had my coffee today…
Cheers

EDIT: I should say for each combination I perform a fairly lengthy function on the combination, so I don’t want to repeat combinations I’ve already done.

EDIT: Any better way than this?

            n = number of races;
            for ( int i = 0; i < n; i++ ) {
                for ( int j = i + 1; j < n; j++ ) {
                    for ( int k = j + 1; k < n; k++ ) {
                        for (int l = k + 1; l < n; l++) {
                            //for each combination of 4 separate sets
                            for(int p = 0; p < races.get(i).getHorses().size(); p++){
                                for(int q = 0; q < races.get(j).getHorses().size(); q++){
                                    for(int r = 0; r < races.get(k).getHorses().size(); r++){
                                        for(int s = 0; s < races.get(l).getHorses().size(); s++){
                                            //each combination of 4 horses
                                            races.get(i).getHorses().get(p)
                                            races.get(j).getHorses().get(q)
                                            races.get(k).getHorses().get(r)
                                            races.get(l).getHorses().get(s)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
  • 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. Editorial Team
    Editorial Team
    2026-06-17T18:13:23+00:00Added an answer on June 17, 2026 at 6:13 pm

    Basically you have two problems. One to choose 4 races out of the 10 total (order doesn’t matter), which is 10! / (6! * 4!) or 210 combinations. Then, for each combination of 4 races you can choose any of the 8 horses in each race, which is 8^4 or 4096.

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

Sidebar

Related Questions

I'm trying to build an algorithm in java, which in ugly way looks like
I'm trying build a method which returns the shortest path from one node to
I'm trying to build up an algorithm that downloads a JPEG image from an
I'm trying to create a data extractor algoritm from group buying sites to build
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying to figure out an algorithm which can look at raw rgba pixels
I'm trying to build a filtering system for products. Products have many attributes including
I have binary A , which is a debug build with accompanying symbols --
I am trying to build spam filtering application using text categorization. From where should
I am trying to build my own Media Container Format . Which should for

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.