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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:21:31+00:00 2026-05-30T07:21:31+00:00

We need to make some small program for school that rolls 5 dices and

  • 0

We need to make some small program for school that rolls 5 dices and see if you get a three of a kind with it, if so, increase points etc.

The problem isnt to reading out the dice, I have the knowledge to get it done, but I want it to be a little efficient, not a ugly piece of code that takes up half a page. I have found ways to filter out the the duplicates in an array, but not the other way around. It rolls with 5 dices, so its an array with 5 numbers, is there like a built in function or a nice, efficient way of returning the number that has been rolled three times or return null if none of the number are rolled three times?

Hope anyone can push me in the right direction. 🙂

  • 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-30T07:21:33+00:00Added an answer on May 30, 2026 at 7:21 am

    One approach is to store a 6-element array containing the count of how many dice have that face. Loop through the 5 dice and increment the appropriate face’s total count.

    var rolls = new List<Roll>();
    // run as many rolls as you want. e.g.:
    rolls.Add(new Roll(5));
    var threeOfAKindRolls = rolls.Where(r => r.HasThreeOfAKind());
    
    public class Roll
    {
         public Roll( int diceCount )
         {
              // Do your random generation here for the number of dice
    
             DiceResults = new int[0]; // your results.
             ResultCounts = new int[6]; // assuming 6 sided die
    
             foreach (var diceResult in DiceResults)
             {
                 ResultCounts[diceResult]++;
             }
         }
    
         public int[] DiceResults { get; private set; }
    
         public int[] ResultCounts { get; private set; }
    
         public bool HasThreeOfAKind()
         {
             return ResultCounts.Any(count => count >= 3);
         }
    }
    

    This code can be shortened somewhat if you don’t need the result counts to perform other tests on the results:

         public Roll( int diceCount )
         {
              // Do your random generation here for the number of dice
             DiceResults = new int[0]; // your results.
         }
    
         public bool HasThreeOfAKind()
         {
             ResultCounts = new int[6]; // assuming 6 sided die
             foreach (var diceResult in DiceResults)
             {
                 // Increment and shortcut if the previous value was 2
                 if( (ResultCounts[diceResult]++) == 2) return true;
             }
             return false;
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a small program more robust and I need some help
I need to make some benchmarks on a small database (64MB) and I need
I need to make some reflective method calls in Java. Those calls will include
I need to make some code to talk to a SOAP web service. Unfortunately
I need to make some commits using Git but I would like the timestamp
I need to make some changes to an old Oracle stored procedure on an
I am C++ programmer and I need to make some changes to VB6 code.
In a .NET 3.0 project, I need to make some calls via P/Invoke (specifically
I need to make use of some OWL ontologies in c#. Does anyone have
I need to download file from FTP server and make some changes on it

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.