Created
June 4, 2020 04:19
-
-
Save devflow/2383a6403738983a4c7ebb30e1e770e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require("moment"); | |
const crypto = require('crypto') | |
const RAW_DATA = [{"d":"2020.04.11","v":[2,5,14,28,31,32,20]},{"d":"2020.04.12","v":[2,5,14,28,31,32,20]}] | |
const DEFAULT_DATE_FORMAT = "YYYY.MM.DD" | |
const DEFAULT_REPEAT = 100 | |
function calcPowerpack(start, end) { | |
let start_date = moment(start, DEFAULT_DATE_FORMAT).startOf('day'), | |
end_date = moment(end, DEFAULT_DATE_FORMAT).endOf('day'), | |
powerpack = Array.from(new Array(45),()=>DEFAULT_REPEAT) | |
RAW_DATA.forEach(e => { | |
let date = moment(e.d, DEFAULT_DATE_FORMAT) | |
if (date.isBetween(start_date, end_date)) { | |
e.v.forEach(v => { | |
powerpack[v]++ | |
}) | |
} | |
}) | |
let pureBox = [] | |
for(const [powerIdx, powerVal] of powerpack.entries()) { | |
for(var i = 0; i < powerVal; i++) { | |
pureBox.push(powerIdx + 1) | |
} | |
} | |
let pickBox = [] | |
for(let pickIdx = 0; pickIdx < 6; pickIdx++) { | |
var picked = pureBox[Math.round((pureBox.length - 1) * (parseInt(crypto.randomBytes(1).toString('hex'), 16) / 255))] | |
pureBox = pureBox.filter(v => v != picked) | |
pickBox.push(picked) | |
} | |
return pickBox.sort((a, b) => a - b) | |
} | |
function howManyWin(pickSet) { | |
let winResult = [0, 0, 0, 0] // least 4 matched | |
RAW_DATA.forEach(e => { | |
let mat = e.v.reduce((p, n) => p + (pickSet.includes(n) ? 1 : 0), 0) | |
if (mat > 3) { | |
winResult[mat - 3]++ | |
} | |
}) | |
return winResult | |
} | |
for(let i = 0; i < 5; i++) { | |
let pp = calcPowerpack("2015.03.01", "2020.12.01"); | |
console.log(pp, "\t\t", howManyWin(pp)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment