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

  • SEARCH
  • Home
  • 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 801699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:28:56+00:00 2026-05-14T23:28:56+00:00

In cases where order does matter, it’s rather easy to generate the matrix of

  • 0

In cases where order does matter, it’s rather easy to generate the matrix of all possible outcomes. One way for doing this is using expand.grid as shown here.

What if it doesn’t?

If I’m right, the number of possible combinations is (S+N-1)!/S!(N-1)!, where S is the number of dice, each with N sides numbered 1 through N. (It is different from the well known combinations formula because it is possible for the same number to appear on more than one dice). For example, when throwing four six-sided dice, N=6 and S=4, so the number of possible combinations is (4+6-1)!/4!(6-1)! = 9!/4!x5! = 126. How can I generate a matrix of these 126 possible outcomes?

Thank you.

  • 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-05-14T23:28:57+00:00Added an answer on May 14, 2026 at 11:28 pm

    Here is code which gd047 and Marek were kind enough to provide.

    S <- 6 
    N <- 4 
    n <- choose(S+N-1,N) 
    outcomes <- t(combn(S+N-1,N,sort)) - matrix(rep(c(0:(N-1)),each=n),nrow=n)
    

    Note: this is optimal in the sense that it does not try to generate all and then throw away the dupes. It actually generates only those that are required.

    An explanation of why it works:

    The possible numbers on the dice are 1 to N.

    Suppose you are given a possible combination of the dice numbers: x1 , x2 , …, xS where S is the number of dice.

    Since the order does not matter, we can assume that

    x1 ≤ x2 ≤ …, ≤ xS.

    Now consider the sequence x1, x2 + 1, x3 + 2, …, xS + S-1.

    (Eg: 1,1,1 becomes 1,1+1,1+2 = 1,2,3).

    This new sequence has numbers from 1 to N+S-1 and all numbers are distinct.

    This mapping from your dice sequence to new one we created is 1-1 and easily reversible.

    Thus to generate a possible combination of S dice with numbers 1 to N, all you need to do is to generate all N+S-1 Choose S combinations of S numbers from 1, 2, …, N+S-1. Given such a combination, you sort it, subtract 0 from the smallest, 1 from the second smallest and so on to get your dice number combination for S dice numbered 1 to N.

    For instance, say N = 6 and S = 3.

    You generate a combo of 3 numbers from 1 to 6+3-1 = 8, i.e 3 numbers from 1,2,…,8.

    Say you get 3,6,7. This translates to 3, 6-1, 7-2 = 3,5,5.

    If you got 1,2,8. This would translate to 1,1,6.

    Incidentally, this mapping also proves the formula you have.

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

Sidebar

Related Questions

I have some SQL that does an order by case statement. It works fine.
What are the cases where you'd use a modal popup ? Does it interrupt
In order to perform a case-sensitive search/replace on a table in a SQL Server
What business cases are there for using Markov chains? I've seen the sort of
In which cases would you use which? Is there much of a difference? Which
In what cases is it necessary to synchronize access to instance members? I understand
Are use cases just multiple user stories?? What are the benefits of using user
In which cases, except development, would you prefer XAMPP over a complete installation and
While I've seen rare cases where private inheritance was needed, I've never encountered a
It seems that in some cases, if you end up with nested modalPopups wrapped

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.