I was curious as to what it would take to mathematically solve lotto. Just For Fun.
So I decided to find out exactly how many tickets I would need to buy, if I wanted to win the next Week's Lotto.
MY GOAL IS TO CREATE EVERY SINGLE TICKET POSSIBLE
I wrote a small program, which can generate every possible Lotto Ticket. Works fine, but it has two problems I can't figure out how to solve:
Every time i work with larger values or large ranges Eg 6*49 the App FREEZES for hours calculating, in the end the App crashes. But if I try to calculate small values and ranges eg all possible 3*5 LOTTO tickets THE PROGRAM Works fine No Crash (3*5== means .... Amount of numbers*The Biggest Number)
Problem two is: I do not know how to make the program stop. I have some End-results but I cannot figure out the equation to get to the end results or make the (WHILE LOOP STOP) program stop working. At the moment I just set it so that if it makes a million duplicate tickets. There are no more possible tickets to make, Exit Now.
The results i get from the experiment are :
3*3=1
3*4=4
3*5=10 ( ie 10 maximum possible tickets)
3*6=20
3*7=35
3*8=56
Or If i work With 4s
4*4=1
4*5=5
4*6=15
4*7=35
4*8=70
or if i use 6s
6*6=1
6*7=7
6*8=28
6*9=84
There is website that can easily calculate it but i have no idea what the equation is:
http://www.lotterynumberspro.com/lottery-odds-calculator.php
My code so far
//******************************Start Values*******************************************************************************
NSMutableArray*starArray=[[NSMutableArray alloc]initWithCapacity:Rangesize];
NSMutableSet *aSet;
int x;
for (x=1; x<=Rangesize; x++) {[starArray addObject:@(x)] ;}
NSMutableArray*allStartValues=[[NSMutableArray alloc]initWithArray:starArray];
NSLog(@"First ticket = %@",[allStartValues componentsJoinedByString:@"_"]);
//***************************Master Array with one object*****************
NSMutableArray*masterArray=[[NSMutableArray alloc]initWithObjects:allStartValues, nil];
NSLog(@"The masterArray initialized = %@",[masterArray componentsJoinedByString:@"_"]);
//****************************************Search Master for instances of new ticket*************
int count=0;
NSMutableString *string = [NSMutableString string];
while ([masterArray containsObject:allStartValues]&& count<=100000) {
NSMutableSet *aSet2=[[NSMutableSet alloc]initWithCapacity:Rangesize];
while(([aSet2 count]!=Rangesize))
{
int Randnum = (arc4random() % BnSize)+1;
[aSet2 addObject:[NSNumber numberWithInt:Randnum]];
}
NSArray *arrayOfUniqueRandomNumbers = [aSet2 allObjects];
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES];
NSArray*new=[arrayOfUniqueRandomNumbers sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
for(NSArray*EachElement in masterArray)
{
if ([masterArray containsObject:new]) {
count++;
break;
}
else {
NSLog(@"ticket %@ Pass to add to Master",[new componentsJoinedByString:@"_"]);
[masterArray addObject:new];
// NSLog(@"The masterArray updated = %@",[masterArray componentsJoinedByString:@"_"]);
break;
}
}
}
int c=1;
for (NSArray*element in masterArray) {
[string appendString:[NSString stringWithFormat:@"Ticket (%i) is >> %@ \n",c ,[element componentsJoinedByString:@"_"]]];
_Scroll.text=string;
c++;
//NSLog(@"array size = %i",[masterArray count]);
}
}
@end
ANYONE KNOW HOW TO MAKE THIS PROGRAM BETTER??