Thread: Logic To Find Least Common Number Combination

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    10

    Logic To Find Least Common Number Combination

    Hello,
    I have been struggling with this program.
    I am somewhat new to c and suck at logic.
    I have a personal program I want to make that I will try to get extra credit for in school.
    I have a printed set of winning lottery numbers form the last 10 years.
    I chose the easiest one do do logically which is just 5 numbers none repeating.
    I am trying to find out how I can print the least common 10 sets.
    I think if there are any set which have not been picked I would have to print all of those because logically they would all be equal, then print sequentially the sets least picked up to 10.

    I have pseudocode which I am sure is wrong but will post it just to show that I am trying. My first attempt was to add the numbers but quickly realized that that wouldn't work

    Any help would be greatly appreciated.

    5 Nums Pseudocode

    Code:
    Read Nums
    Parse Into Ints
    Make Array [185] //39+38+37+36+35 The highest the numbers added together can go
    
    
    //LOGIC
    
    Loop
        Take Set of nums
        arrange them every order possible // 5 ways
        Somehow hold this set of 5 // Maybe a multidimensional array
                                    // where each spot in main array held an array with the 5 combinations
                                    //The seccond deimsion af the array would have an extra spot
        incremement the extra spot in array by one
        
    End 
    
    Loop While Counter is less than  10
        Counter = 0
        Look at the 5th element in the 2nd dimension of each array element and find the lowest number
        print number
        increment number by 100  // So next time around this number wont get picked
        Increment Counter
    End

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I don't mean to be unkind, but WTF?

    The problem description is:

    1) You have some winning lottery tickets numbers for the past 10 years.

    2) You want to find the least common set.

    Let's do this in plain English, for starters. Thanks for showing your work on it, but put it aside for now, please.


    For #2, put the numbers into an array, and sort the numbers. That will put all the duplicate sets, adjacent to each other. Now scan through the sets of numbers, and count up the lowest amount of repetition sets that you have, in this way:

    a) count up the repetitions you have in the current stream of sets, as you move through the array

    b) when you no longer have a repetition, compare the number of repetitions you have counted so far, with the lowest number of repetitions you have found throughout your search. (you will use two separate variables here). If the current number of repetitions is less than the former lowest number of repetitions you found, then assign the new lowest repetition number, to the maximum lowest repetition number.

    And continue your counting of the current repetitions.

    In other words, it's just like you were looking for the lowest number in a set of numbers, except you are looking for the lowest count of repetitions.

    Sounds a bit like you're drifting into the "gambler's fallacy" here. Just because a number has been drawn before, that doesn't decrease the odds of it being drawn again, by a random choice of numbers for a lottery ticket.

    If you had a number drawing machine, say the numbers were on ping pong balls, and they were all in a big tumbler machine (common), now IF the tumbler had say, 100 balls with the same number on it (for every number, so thousands of balls), and every time a number was picked, it was REMOVED from the tumbler, then your method would be PERFECT for increasing your odds of winning.

    Alas, that's not the case with any lottery I've heard about.
    Last edited by Adak; 11-22-2013 at 07:04 PM.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    It's good that you're trying to work out the logic before jumping into code, but I'm also not quite sure what you mean.

    Quote Originally Posted by EdMarx
    I think if there are any set which have not been picked I would have to print all of those because logically they would all be equal, then print sequentially the sets least picked up to 10.
    From this is sounds like you want to display all the combinations that have never come up, then the ones that have only come up once and so on. I don't know what the lottery is like wherever you are, so I'm assuming that order doesn't matter, and that you pick 5 numbers from 1-39.

    In that case you'll need a way to calculate every possible combination of numbers: Combination - Wikipedia, the free encyclopedia will give you the number of combinations you're expecting. 5 numbers 1-39 is 575,757 combinations.

    Hmmm - I think that's a lost cause. Writing a program to do this would probably be a decent learning exercise -- it's good to figure out how to make a computer do what you do instinctively. Useful in this context though? No.... Makes you realise what a con the lottery is really.

    Probably best to do what Adak has suggested and get the results you have in and counted up. Then see what percentage of the combination space you've covered.... then never play the lottery again

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    You say you have records of lottery numbers for 520 lottery games (assuming one game per week for ten years). Given that there are 575757 combinations (according the post by smokeyangel), it is not likely that any of the combinations occur more than once in this relatively short record of games. So I'm not sure the purpose of finding the "least common" combination would mean. Do you mean to count how often the individual numbers appear in anywhere in the winning games?

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    10
    Sorry I didnt get an email saying anyone replied to this thread so I havent checked it since I wrote it.
    I glad to see so many responses. Up front I would like to say Im relatively this program is more of an attempt of me using math in my code more than it is anything else.
    @adak
    Thanks for the help.
    Wen you say "move through the array" you are referring to the complete 10 year archive of numbers not each individual number in each number set correct? So if the array is the complete sheet of numbers and if each set of 5 numbers are parsed in individual elements wouldnt that be a multi dimensional array. U would parse each number correct?
    And in step b u mean 2 variables or pointers maybe to find the difference between the lowest matching set and highest?
    But then How would I account for all of the combinations that have not been picked?

    What if I just wrote something that counted all of the sets.
    Put a corresponding number to each set. Either the number of matches or a null for no matches.
    Then went through the numbers returning all the nulls and the ten lowest numbers (probably all 1 pick).

    @smokeyangel
    If I have 2 binary units the possible combinations would be 4 right. 2* 2
    If I have 3 units that have 1-3 options the possible combinations would be 9 right. 3 * 3.
    So wouldnt the probability of 5 numbers at 39 each be 39 * 38 * 37 * 36 * 35 (accounting for each ball removal)?

    Either way c99tutorial had a good point. If most of the possibilites have never been picked then this program is kinda pointless.
    I have 7320 combinations by the way. Which is still a very low number.
    Writing a program to do this would probably be a decent learning exercise
    Is exacly why im doing it.
    Ill remove a ball (the last number in each set). This will give my program a better chance of making me feel like im not wasting my time. Im just getting kind of sick of writing programs that are purely hypothetical (school) and wanted to something real world.

    BTW I dont play the lottery. Instead every day I take a dollar bill, dip it in ketchup, tape the ketchup soaked bill to my forehead for 4 hours. I then then wash off the ketchup and
    put it back in my wallet. You may think this is kind of silly but Ive been doing it for 10 years and so far have broken even. Cant say the same for people who play the lotto.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Thumbs up for the Ketchup trick! Lovely!! <ROFL!>

    If you want the extra credit, and you're learning, then it's not pointless. It's not like you're expecting to become a millionaire with this, so I don't see the relevance of probability here.

    Best thing is to post 7 numbers, with and without repeats, and show what you want to do, in detail, by hand. There are a lot of ideas here, and we need to narrow down to just what you need.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. combination of number program in c
    By sunil pandey in forum C Programming
    Replies: 5
    Last Post: 01-04-2013, 04:40 PM
  2. Replies: 56
    Last Post: 09-03-2012, 12:00 PM
  3. c++ program-the number of common digits of 2 numbers a & b
    By Sky_Daughter in forum C++ Programming
    Replies: 3
    Last Post: 12-22-2011, 05:03 PM
  4. find out logic for the program
    By cooldude in forum C Programming
    Replies: 9
    Last Post: 09-08-2009, 01:52 PM
  5. Replies: 8
    Last Post: 09-27-2008, 07:32 PM

Tags for this Thread