Lottery Code Optimization (Not enough RAM)
Show older comments
So I want to create a matrix with all the lottery combinations. 6 numbers between 1 and 49. This gives 13,983,816 possible combinations. From this matrix I will start reducing some combinations such as 6 consecutive numbers, all odd numbers, etc. to theoretically increase my chances. Anyway, I'm stuck at the phase of creating the actual matrix, I only have 16GB of RAM which is not enough. This is my code:
close all; clear all; clc
opt_a=zeros(0,49^6);
opt_b=zeros(0,49^6);
opt_c=zeros(0,49^6);
opt_d=zeros(0,49^6);
opt_e=zeros(0,49^6);
opt_f=zeros(0,49^6);
index=0;
for a=1:49
for b=1:49
for c=1:49
for d=1:49
for e=1:49
for f=1:49
index=index+1;
opt_a(index)=a;
opt_b(index)=b;
opt_c(index)=c;
opt_d(index)=d;
opt_e(index)=e;
opt_f(index)=f;
end
end
end
end
end
end
options=[opt_a' opt_b' opt_c' opt_d' opt_e' opt_f']
Is there anyway to make this code finish running with 16GB of RAM? If not, can I split the code somehow into parts and assemble the parts to create the matrix. Or maybe there already exists such matrix in a txt.file which I can import into Matlab?
Thanks
3 Comments
Image Analyst
on 20 Nov 2015
The first argument of zeros() cannot be 0. You can't have a 0 row by 49^6 column vector.
John D'Errico
on 21 Nov 2015
Edited: John D'Errico
on 21 Nov 2015
How would not having all the odd numbers theoretically increase your chances? (Hint: it does not.) Similarly for consecutive numbers.
Second hint:
help nchoosek
Third hint:
A lottery ticket is a poor way to invest your money in general.
Walter Roberson
on 21 Nov 2015
Image Analyst: you certainly can use 0 as a argument to zeros.
>> z = zeros(0,49^6)
z =
Empty matrix: 0-by-13841287201
Answers (1)
Walter Roberson
on 20 Nov 2015
"From this matrix I will start reducing some combinations such as 6 consecutive numbers, all odd numbers, etc. to theoretically increase my chances"
To theoretically increase your chances of what? Certainly not your chances of winning: the combination
1 2 3 4 5 6
is exactly the same probability as the combination
14 17 32 38 41 47
unless the random number generator is biased.
3 Comments
Image Analyst
on 23 Nov 2015
I think maybe one reason for the Gambler's fallacy is that people seem to have an intuitive agreement with the concept of regression toward the mean, which states that after a series of outliers, the trend will be to return to the long term historical or group mean. It's often used in sports training. For example this statistics site says: "Do a fitness test on a bunch of subjects. Rank the subjects by their score and select the bottom half of the bunch. Retest the bottom half. The average score of the bottom half will probably improve somewhat on retest. Similarly, the average score of the top half will probably drop somewhat on retest. These changes in performance are called regression to the mean. The name refers to a tendency for subjects who score below average on a test to do better next time, and for those who score above average to do worse." If an athlete runs his personal best (fastest) race, what do you think the probability is that he'll trend even faster in upcoming races versus trending back towards his historical mean speed?
So I think people think if you have, say 32 "heads" coin flips in a row, that soon it will return to it's historical pattern of heads and tails that change more rapidly. True, that's not true when predicting the next coin flip, but I think people think that that pattern of heads-only-flips won't continue. Perhaps they shouldn't though. I think a maximum likelihood analysis of flips that are like THHTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH might predict that the next one should be a head. I mean it seems more likely to believe that the next one would be a head and that the coin is not fair, rather than to ASSUME the coin is fair and that there is an equal probability of Heads and Tails. Without any prior knowledge, it doesn't seem likely that a coin doing such a pattern is fair and seems more likely to assume it's not fair.
Walter Roberson
on 28 Nov 2015
Image Analyst
on 28 Nov 2015
Interesting. I wonder if their coin was not fair/evenly weighted. What gave rise to the bias?
Also I wonder why multiple researchers over decades have all disproved hot hand and yet these guys got a contrary result. Supposedly all the others before them didn't know what the heck they were talking about???
And if the streak continues, then the historical mean will start to change and by definition they will eventually start to regress towards the mean.
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!