Skip to content

Instantly share code, notes, and snippets.

@erickvieira
Last active December 28, 2018 11:05
Show Gist options
  • Save erickvieira/334ab2dbcf1640a349c075bcb9cf26ca to your computer and use it in GitHub Desktop.
Save erickvieira/334ab2dbcf1640a349c075bcb9cf26ca to your computer and use it in GitHub Desktop.
Software de sorteio dos números da mega sena.
const sorteios = {
s2009: '10 27 40 46 49 58',
s2010: '02 10 34 37 43 50',
s2011: '03 04 29 36 45 55',
s2012: '14 32 33 36 41 52',
s2013: '20 30 36 38 47 53',
s2014: '01 05 11 16 20 56',
s2015: '02 18 31 42 51 56',
s2016: '05 11 22 24 51 53',
s2018: '03 06 10 17 34 37'
}
Object.keys(sorteios).forEach(k => {
sorteios[k] = sorteios[k].split(' ');
});
function sortear() {
let arr = [];
let cont = 0;
while (cont <= 5) {
arr.push(Math.floor(Math.random() * 60) + 1);
cont++;
}
return arr;
}
function criarCartela() {
let arr = [];
let cont = 1;
while (cont <= 60) {
arr.push({num: cont, sort: 0});
cont++;
}
return arr;
}
let maisSorteados = [];
(function() {
let sorteios = [];
let cartela = criarCartela();
let cont = 0;
while (cont <= 6999999) {
let sorteio = sortear();
sorteio.forEach(s => {
sorteios.push(sorteio);
try {
cartela[s - 1].sort++;
} catch (e) {
console.table(cartela);
}
});
cont++;
}
cartela.sort((x, y) => {
return x.sort - y.sort;
}).forEach(s => {
maisSorteados.push(s.num);
});
console.log(`${maisSorteados.reverse().slice(0,6).sort((x, y) => x - y).toString()}\n${maisSorteados.reverse().slice(6,12).sort((x, y) => x - y).toString()}`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment