Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to calculate in c# the possibility of this game

How to calculate in c# the possibility of this game

Scheduled Pinned Locked Moved C#
csharpgame-devtutorialquestion
30 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Exoskeletor

    Im trying to create an app to calculate the posibilities of a game. In the game every time we play, from 80 numbers only 20 of them are randomly selected and from the 80 numbers i can select maximum 12 of them that they might win. I want to calculate the posibility to have select the winning x numbers from my selected numbers. (I mean if i have selected 10 numbers and the 7 of them win i want the percentage possibility for that.) I know that the type to check that is: Ρ(y,x) = (y per x)*(80-y per 20-x)/ (80 per 20) where y are the numbers i have selected to play and x are the numbers that won. How i can convert that to c#? thanks

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #2

    What have you tried? Where are you stuck? What help do you need?

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    E 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      What have you tried? Where are you stuck? What help do you need?

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      E Offline
      E Offline
      Exoskeletor
      wrote on last edited by
      #3

      I dont know how to convert this equation into c#. i cant understand this per in the type Ρ(y,x) = (y per x)*(80-y per 20-x)/ (80 per 20) is. what per means. I havent try anything since i cant udnerstand it. i already said where i am stuck and what help i need

      OriginalGriffO 1 Reply Last reply
      0
      • E Exoskeletor

        I dont know how to convert this equation into c#. i cant understand this per in the type Ρ(y,x) = (y per x)*(80-y per 20-x)/ (80 per 20) is. what per means. I havent try anything since i cant udnerstand it. i already said where i am stuck and what help i need

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #4

        Well, where did you get the equation from? They will probably define y per x for you. Did you look?

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        E 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Well, where did you get the equation from? They will probably define y per x for you. Did you look?

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          E Offline
          E Offline
          Exoskeletor
          wrote on last edited by
          #5

          it was in greek and it didnt say anything but this also is the same equation: https://nihilistslab.com/html/products/engb/kinostatistics/Images/Pn(k).png[^] it is called HyperGeometric Distribution. Someone has created in codeproject.com a tool to convert equations to c# but i cant understand how i can write something like a HyperGeometric Distribution

          OriginalGriffO 1 Reply Last reply
          0
          • E Exoskeletor

            it was in greek and it didnt say anything but this also is the same equation: https://nihilistslab.com/html/products/engb/kinostatistics/Images/Pn(k).png[^] it is called HyperGeometric Distribution. Someone has created in codeproject.com a tool to convert equations to c# but i cant understand how i can write something like a HyperGeometric Distribution

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #6

            No, that's a mess of pixels with no meaning to anybody... And as for the Greek, either look for an English language description or use Google Translate. Did you try Wikipedia: Hypergeometric distribution - Wikipedia[^] ?

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            E 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              No, that's a mess of pixels with no meaning to anybody... And as for the Greek, either look for an English language description or use Google Translate. Did you try Wikipedia: Hypergeometric distribution - Wikipedia[^] ?

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              E Offline
              E Offline
              Exoskeletor
              wrote on last edited by
              #7

              Yes i tried all that, here is exactly what i want Kino Statistics Mathematical Analysis[^] I want this equation in c#. i show online some c# codes for Hypergeometric distribution but they dont give probability and are very complex

              E OriginalGriffO 2 Replies Last reply
              0
              • E Exoskeletor

                Yes i tried all that, here is exactly what i want Kino Statistics Mathematical Analysis[^] I want this equation in c#. i show online some c# codes for Hypergeometric distribution but they dont give probability and are very complex

                E Offline
                E Offline
                Exoskeletor
                wrote on last edited by
                #8

                I think i have managed to convert it to a simpler equation: what i want is this to c# now: (n!/(k!*(n-k)!)*(80-n)!/((20-k)!*((80-n)-(20-k))!))/(80!/(20!*(80-20)!))

                1 Reply Last reply
                0
                • E Exoskeletor

                  Yes i tried all that, here is exactly what i want Kino Statistics Mathematical Analysis[^] I want this equation in c#. i show online some c# codes for Hypergeometric distribution but they dont give probability and are very complex

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #9

                  So what's the problem? that link leads you through the process of getting a probability from the inputs, so what have you tried to implement it? Where are you stuck? What help do you need? (Other than "somebody else to do all the work for me" which isn't the idea of this site at all.)

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  E 2 Replies Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    So what's the problem? that link leads you through the process of getting a probability from the inputs, so what have you tried to implement it? Where are you stuck? What help do you need? (Other than "somebody else to do all the work for me" which isn't the idea of this site at all.)

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                    E Offline
                    E Offline
                    Exoskeletor
                    wrote on last edited by
                    #10

                    I think i was pretty clear to what i want. I dont know how a equation is being translated to c#. If this to you is translated "to someone else do the work for me" then i cant do anyhting about that, just skip this topin, you dont HAVE to answer something. asking the same question again and again how it helps?

                    OriginalGriffO 1 Reply Last reply
                    0
                    • E Exoskeletor

                      I think i was pretty clear to what i want. I dont know how a equation is being translated to c#. If this to you is translated "to someone else do the work for me" then i cant do anyhting about that, just skip this topin, you dont HAVE to answer something. asking the same question again and again how it helps?

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #11

                      Yeah, it's pretty clear: you want someone else to do the work for you. I'm trying to avoid the derision that can attract to you by getting you to think about your task and actually try to do the work yourself, or at least try. But so far, you've shown no sign at all of trying to implement anything yourself! We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you. Plus, if we just "hand you the solution" you don't learn anything useful from that, and the next time you have to do a similar task you have to ask again, and again, and again ... people learn by doing, not by looking at results! So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in! Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      E 1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        Yeah, it's pretty clear: you want someone else to do the work for you. I'm trying to avoid the derision that can attract to you by getting you to think about your task and actually try to do the work yourself, or at least try. But so far, you've shown no sign at all of trying to implement anything yourself! We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you. Plus, if we just "hand you the solution" you don't learn anything useful from that, and the next time you have to do a similar task you have to ask again, and again, and again ... people learn by doing, not by looking at results! So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in! Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                        E Offline
                        E Offline
                        Exoskeletor
                        wrote on last edited by
                        #12

                        we dont have to do this converstation. i dont want you to solve anything for me or toexplain what solving for me means. Lets take it from the beginning Facts: nobody wants to do the work for the other Problem: how to convert equation to c# With those facts in this problem where someone starts? as i pointed already in a previous post i try to convert this equation to maths (n!/(k!*(n-k)!)*(80-n)!/((20-k)!*((80-n)-(20-k))!))/(80!/(20!*(80-20)!)) and you said it is pretty clear i want you to do the work for me.. you are obvious wrong but lets not discuss that either if you still want to think im trying to find someone to do my the job.. great. (you should REALLY check what you think is pretty clear since you are posting very often here, my messages didnt at all show what you are saying, i have share many and many informations) Now to the point: i used this tool (as i methioned already in the previous posts) Converting math equations to C#[^] and it has create some Factorial() procedures, c# cant recognise them, those exist in a library or something

                        OriginalGriffO 1 Reply Last reply
                        0
                        • E Exoskeletor

                          we dont have to do this converstation. i dont want you to solve anything for me or toexplain what solving for me means. Lets take it from the beginning Facts: nobody wants to do the work for the other Problem: how to convert equation to c# With those facts in this problem where someone starts? as i pointed already in a previous post i try to convert this equation to maths (n!/(k!*(n-k)!)*(80-n)!/((20-k)!*((80-n)-(20-k))!))/(80!/(20!*(80-20)!)) and you said it is pretty clear i want you to do the work for me.. you are obvious wrong but lets not discuss that either if you still want to think im trying to find someone to do my the job.. great. (you should REALLY check what you think is pretty clear since you are posting very often here, my messages didnt at all show what you are saying, i have share many and many informations) Now to the point: i used this tool (as i methioned already in the previous posts) Converting math equations to C#[^] and it has create some Factorial() procedures, c# cant recognise them, those exist in a library or something

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #13

                          That's because C# doesn't contain a factorial function - but it's trivial to create one yourself, it's one of the first exercise beginners are often given. Recursive or iterative, it's simple either way:

                              private static int FactorialRecursive(int x)
                                  {
                                  return (x > 1 ? x \* FactorialRecursive(x - 1) : 1);
                                  }
                              private static int FactorialIterative(int x)
                                  {
                                  int f = 1;
                                  while (x > 1)
                                      {
                                      f \*= x--;
                                      }
                                  return f;
                                  }
                          

                          So why couldn't you just write those? Or google for them?

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          E 1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            That's because C# doesn't contain a factorial function - but it's trivial to create one yourself, it's one of the first exercise beginners are often given. Recursive or iterative, it's simple either way:

                                private static int FactorialRecursive(int x)
                                    {
                                    return (x > 1 ? x \* FactorialRecursive(x - 1) : 1);
                                    }
                                private static int FactorialIterative(int x)
                                    {
                                    int f = 1;
                                    while (x > 1)
                                        {
                                        f \*= x--;
                                        }
                                    return f;
                                    }
                            

                            So why couldn't you just write those? Or google for them?

                            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                            E Offline
                            E Offline
                            Exoskeletor
                            wrote on last edited by
                            #14

                            Because maybe im missing something and this function exists. I dont prefer always solving anything by my own because im not sure if it the best approach. Thanks, i think ive got it from here. I will post again here only if i have code to post since i see that if i dont have code people here believe that i intentionally dont have code and i dont those negative situations. Thanks

                            L 1 Reply Last reply
                            0
                            • E Exoskeletor

                              Because maybe im missing something and this function exists. I dont prefer always solving anything by my own because im not sure if it the best approach. Thanks, i think ive got it from here. I will post again here only if i have code to post since i see that if i dont have code people here believe that i intentionally dont have code and i dont those negative situations. Thanks

                              L Offline
                              L Offline
                              Luc Pattyn
                              wrote on last edited by
                              #15

                              I'm curious what your code will look like; you are in for a couple of surprises when you discover the difference between theory and practice... :)

                              Luc Pattyn [My Articles] If you can't find it on YouTube try TikTok...

                              E 1 Reply Last reply
                              0
                              • L Luc Pattyn

                                I'm curious what your code will look like; you are in for a couple of surprises when you discover the difference between theory and practice... :)

                                Luc Pattyn [My Articles] If you can't find it on YouTube try TikTok...

                                E Offline
                                E Offline
                                Exoskeletor
                                wrote on last edited by
                                #16

                                Right now im at this:

                                    private int CalculateProbabilityOfDrawNumbersFromAllNumbers(int drawNumbers, int allNumbers)
                                    {
                                        return ((Factorial(allNumbers) \* Factorial(80 - allNumbers)) / (((Factorial(80) \* ((Factorial(drawNumbers) \* Factorial(allNumbers - drawNumbers)) \* (Factorial(20 - drawNumbers) \* Factorial(((80 - allNumbers) - (20 - drawNumbers)))))) / (Factorial(20) \* Factorial(80 - 20)))));
                                    }
                                
                                    private static int Factorial(int x)
                                    {
                                        int f = 1;
                                        while (x > 1)
                                        {
                                            f \*= x--;
                                        }
                                        return f;
                                    }
                                

                                which gives division by zero and i try to understand if something have gone wrong with all those parenthesis

                                L T 2 Replies Last reply
                                0
                                • E Exoskeletor

                                  Right now im at this:

                                      private int CalculateProbabilityOfDrawNumbersFromAllNumbers(int drawNumbers, int allNumbers)
                                      {
                                          return ((Factorial(allNumbers) \* Factorial(80 - allNumbers)) / (((Factorial(80) \* ((Factorial(drawNumbers) \* Factorial(allNumbers - drawNumbers)) \* (Factorial(20 - drawNumbers) \* Factorial(((80 - allNumbers) - (20 - drawNumbers)))))) / (Factorial(20) \* Factorial(80 - 20)))));
                                      }
                                  
                                      private static int Factorial(int x)
                                      {
                                          int f = 1;
                                          while (x > 1)
                                          {
                                              f \*= x--;
                                          }
                                          return f;
                                      }
                                  

                                  which gives division by zero and i try to understand if something have gone wrong with all those parenthesis

                                  L Offline
                                  L Offline
                                  Luc Pattyn
                                  wrote on last edited by
                                  #17

                                  investigate and learn! :)

                                  Luc Pattyn [My Articles] If you can't find it on YouTube try TikTok...

                                  E 1 Reply Last reply
                                  0
                                  • L Luc Pattyn

                                    investigate and learn! :)

                                    Luc Pattyn [My Articles] If you can't find it on YouTube try TikTok...

                                    E Offline
                                    E Offline
                                    Exoskeletor
                                    wrote on last edited by
                                    #18

                                    thats what i said first!!!

                                    1 Reply Last reply
                                    0
                                    • E Exoskeletor

                                      Right now im at this:

                                          private int CalculateProbabilityOfDrawNumbersFromAllNumbers(int drawNumbers, int allNumbers)
                                          {
                                              return ((Factorial(allNumbers) \* Factorial(80 - allNumbers)) / (((Factorial(80) \* ((Factorial(drawNumbers) \* Factorial(allNumbers - drawNumbers)) \* (Factorial(20 - drawNumbers) \* Factorial(((80 - allNumbers) - (20 - drawNumbers)))))) / (Factorial(20) \* Factorial(80 - 20)))));
                                          }
                                      
                                          private static int Factorial(int x)
                                          {
                                              int f = 1;
                                              while (x > 1)
                                              {
                                                  f \*= x--;
                                              }
                                              return f;
                                          }
                                      

                                      which gives division by zero and i try to understand if something have gone wrong with all those parenthesis

                                      T Online
                                      T Online
                                      trønderen
                                      wrote on last edited by
                                      #19

                                      Small hint: 80! is a number of about 120 decimal digits. An int can hold numbers up to roughly 9 digits.

                                      E 1 Reply Last reply
                                      0
                                      • T trønderen

                                        Small hint: 80! is a number of about 120 decimal digits. An int can hold numbers up to roughly 9 digits.

                                        E Offline
                                        E Offline
                                        Exoskeletor
                                        wrote on last edited by
                                        #20

                                        that wasnt a hint!!! it appears to be the solution cause now this works

                                        using System.IO;
                                        using System;

                                        class Program
                                        {
                                        static void Main()
                                        {
                                        Console.WriteLine(CalculateProbabilityOfDrawNumbersFromAllNumbers(1,1));
                                        }
                                        private static double CalculateProbabilityOfDrawNumbersFromAllNumbers(double drawNumbers, double allNumbers)
                                        {
                                        return Factorial(allNumbers) / (Factorial(drawNumbers) * Factorial(allNumbers - drawNumbers)) * (Factorial(80 - allNumbers) / (Factorial(20 - drawNumbers) * Factorial(80 - allNumbers - (20 - drawNumbers)))) / (Factorial(80) / (Factorial(20) * Factorial(80 - 20)));
                                        }

                                            private static double Factorial(double x)
                                            {
                                                double f = 1;
                                                while (x > 1)
                                                {
                                                    f \*= x--;
                                                }
                                                return f;
                                            }
                                        

                                        }

                                        im not sure why i was getting division by zero error. the int has surpass its largest number and return 0? i will use this crazy code to display it as a percentage without any unnecessary zeros in the end

                                            Console.WriteLine((CalculateProbabilityOfDrawNumbersFromAllNumbers(12,12) \* 100).ToString("F7").TrimEnd(new Char\[\] { '0' } ).TrimEnd(new Char\[\] { '.' } )+"%");
                                        
                                        L E 2 Replies Last reply
                                        0
                                        • E Exoskeletor

                                          that wasnt a hint!!! it appears to be the solution cause now this works

                                          using System.IO;
                                          using System;

                                          class Program
                                          {
                                          static void Main()
                                          {
                                          Console.WriteLine(CalculateProbabilityOfDrawNumbersFromAllNumbers(1,1));
                                          }
                                          private static double CalculateProbabilityOfDrawNumbersFromAllNumbers(double drawNumbers, double allNumbers)
                                          {
                                          return Factorial(allNumbers) / (Factorial(drawNumbers) * Factorial(allNumbers - drawNumbers)) * (Factorial(80 - allNumbers) / (Factorial(20 - drawNumbers) * Factorial(80 - allNumbers - (20 - drawNumbers)))) / (Factorial(80) / (Factorial(20) * Factorial(80 - 20)));
                                          }

                                              private static double Factorial(double x)
                                              {
                                                  double f = 1;
                                                  while (x > 1)
                                                  {
                                                      f \*= x--;
                                                  }
                                                  return f;
                                              }
                                          

                                          }

                                          im not sure why i was getting division by zero error. the int has surpass its largest number and return 0? i will use this crazy code to display it as a percentage without any unnecessary zeros in the end

                                              Console.WriteLine((CalculateProbabilityOfDrawNumbersFromAllNumbers(12,12) \* 100).ToString("F7").TrimEnd(new Char\[\] { '0' } ).TrimEnd(new Char\[\] { '.' } )+"%");
                                          
                                          L Offline
                                          L Offline
                                          Luc Pattyn
                                          wrote on last edited by
                                          #21

                                          Quote:

                                          im not sure why i was getting division by zero error. the int has surpass its largest number and return 0?

                                          Don't just let that go, think, think until you figured it out!

                                          Luc Pattyn [My Articles] If you can't find it on YouTube try TikTok...

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups