Clear Filters
Clear Filters

Lottery Code Optimization (Not enough RAM)

3 views (last 30 days)
john
john on 20 Nov 2015
Commented: Image Analyst on 28 Nov 2015
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
John D'Errico
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
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

Sign in to comment.

Answers (1)

Walter Roberson
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.
I have a suspicion that you also need to read about The Gambler's Fallacy
  3 Comments
Image Analyst
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.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!