Skip to content

Instantly share code, notes, and snippets.

@devflow
Created Jun 4, 2020
Embed
What would you like to do?
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