The title

  • Lucky lottery 1-33, a total of 33 numbers of 6 combinations, a total of more than 1.1 million, through exclusion, screening, customization, output the remaining combinations
  1. Inputable mutability filter:
    1. You can specify a start number and enter six digits to filter combinations. For example, enter 1.1.1.1.1.1. If the value starts with 1, the number of six digits is 02.04.06.08.10.12. (Kou 02 kou 04 kou 06 kou 08 kou 10 kou 12). 6 were 01.03.05.07.09.11 respectively. If 1.2.3.4.5.6 is entered, the six digits are arranged as 02.05.09.14.20.27. (Kou 02 kou 05 kou 09 kou kou 14 kou kou 20 kou kou 27).
    2. And value filter, you can enter the sum value range, such as 80-90, 6-digit combination of values within 80-90
    3. Can be odd even screening, input 3 odd 3 even or 5 odd 1 even
    4. Enter multiple numbers to be excluded, separated by commas, for example, 5,12…
  2. Hard exclusion:
    1. For example, 1.2.3 or 25.26.27
    2. All odd, all even excluded.
    3. To exclude a combination of 6 numbers in 10 consecutive numbers, as in all numbers 1-10.
  3. Can be checked, all hard, variable after screening of the data group, input 6 numbers can be displayed in the data group.

implementation

/* Get the array set */
function getNumArray(m, n, filterCallback, checkArray) {
    console.time('time')

    let count = 0;
    let numArray = [];
    let isInNumArray = false;

    function getArrayByIndex(index, array) {
        let length = m - n + index;
        for (let i = 1; i <= length; i++) {
            if (index > 1 && isIncludeInArray(array, i)) {
                continue;
            }
            let tempArray = [...array, i];
            if(! isAscArray(tempArray)) {continue;
            }
            if (n === index) {
                const currentObj = Object.assign(getArrayObj(tempArray), {
                    array: tempArray,
                    sum: getSum(tempArray),
                    oddNum: getOddEvenNum(tempArray).oddNum,
                    evenNum: getOddEvenNum(tempArray).evenNum,
                    space: getSpaceArray(tempArray),
                });
                if (filterCallback && filterCallback(currentObj)) {
                    continue;
                }
                if (checkArray && (checkArray.join(', ') === tempArray.join(', '))) {
                    isInNumArray = true;
                }
                numArray.push(currentObj);
                count++;
            } else {
                getArrayByIndex(index + 1, tempArray); }}}Copy the code
/* Check if there are duplicate contents */
function isIncludeInArray(array, num) {
    let bool = false;
    let length = array.length;
    for (let i = 0; i < length; i++) {
        if (array[i] === num) {
            bool = true;
            break; }}return bool;
}

/* Check whether an array is ascending */
function isAscArray(array) {
    let bool = true;
    let length = array.length - 1;
    for (let i = 0; i < length; i++) {
        if (array[i + 1] < array[i]) {
            bool = false;
            break; }}return bool;
}

/* Get the array and value */
function getSum(array) {
    let sum = 0;
    array.forEach(item= > {
        sum += item;
    })
    return sum;
}

/* Get the odd and even number of arrays */
function getOddEvenNum(array) {
    let oddNum = 0, evenNum = 0;
    let length = array.length;
    for (let i = 0; i < length; i++) {
        if (array[i] % 2= = =1) {
            oddNum = oddNum + 1;
        }
        if (array[i] % 2= = =0) {
            evenNum = evenNum + 1; }}return {oddNum, evenNum};
}

/* Get the array see the interval array between the numbers */
function getSpaceArray(array) {
    let spaceArray = [];
    let length = array.length - 1;
    for (let i = 0; i < length; i++) {
        spaceArray.push(array[i + 1] - array[i] - 1);
    }
    return spaceArray.join(', ');
}

/* Get the array object */
function getArrayObj(array) {
    let obj = {};
    array.forEach((value, index) = > {
        obj[`n${index + 1}`] = value;
    })
    return obj;
}
Copy the code
/* Check whether the serial number is */
function isSequential(array, count) {
    let bool = false;
    let space = count - 1;
    let length = array.length - space;
    for (let i = 0; i < length; i++) {
        if (array[i + space] - array[i] === space) {
            bool = true;
            break; }}return bool;
}

/* You can specify a starting number and then enter 6 numbers to filter permutations */
function filter1(current, p_start, p_spaceArray) {
    const {n1, space} = current;
    if (p_start && p_spaceArray) {
        let newArray = [...p_spaceArray];
        newArray.shift()
        if(! (n1 === p_start + p_spaceArray[0] && space === newArray.join(', '))) {
            return true; }}return false;
}

/* Filter condition two and value filter */
function filter2(current, p_rangeSumMin, p_rangeSumMax) {
    const {sum} = current;
    if(p_rangeSumMin && ! p_rangeSumMax) {if (sum < p_rangeSumMin) {
            return true}}else if(! p_rangeSumMin && p_rangeSumMax) {if (sum > p_rangeSumMax) {
            return true}}else if (p_rangeSumMin && p_rangeSumMax) {
        if (sum < p_rangeSumMin || sum > p_rangeSumMax) {
            return true}}return false;
}

/* Parity filter */
function filter3(current, p_evenNum, p_oddNum) {
    const {evenNum, oddNum} = current;
    if(p_evenNum && ! p_oddNum) {if(evenNum ! == p_evenNum) {return true}}else if(! p_evenNum && p_oddNum) {if(oddNum ! == p_oddNum) {return true}}else if (p_evenNum && p_oddNum) {
        if(oddNum ! == p_oddNum) {return true}}return false;
}

/* Multiple numbers excluded by filter condition 4 */
function filter4(current, p_filterNums) {
    const {array} = current;
    let length = array.length;
    let bool = false;
    if (p_filterNums) {
        for (let i = 0; i < length; i++) {
            if (p_filterNums.includes(array[i])) {
                bool = true;
                break; }}}return bool;
}
Copy the code
/* Implements the function */
function check_filter_number({ p_start, p_spaceArray, p_rangeSumMin, p_rangeSumMax, p_evenNum, p_oddNum, p_filterNums, p_checkNums }) {
    if (p_start && p_spaceArray) {
        console.log('starting number${p_start}, numeric interval:${p_start}`);
    }
    if (p_rangeSumMin && p_rangeSumMax) {
        console.log('and value range${p_rangeSumMin}-${p_rangeSumMax}`);
    }
    if (p_oddNum && p_evenNum) {
        console.log(Where the odd number:${p_oddNum}And even number:${p_evenNum}`);
    }
    if (p_filterNums) {
        console.log('Exclusion figure${p_filterNums}`);
    }
    return getNumArray(
        33.6.function (currentObj) {
            const {array, n1, n6, oddNum, evenNum} = currentObj;
            return isSequential(array, 3) ||
                (evenNum === 6 || oddNum === 6) ||
                ((n6 - n1) <= 9) ||
                filter1(currentObj, p_start, p_spaceArray) ||
                filter2(currentObj, p_rangeSumMin, p_rangeSumMax) ||
                filter3(currentObj, p_evenNum, p_oddNum) ||
                filter4(currentObj, p_filterNums)
        },
        p_checkNums
    );

}
Copy the code
/* Execute the function */
check_filter_number({
    p_start: 1.p_spaceArray: null.p_rangeSumMin: 80.p_rangeSumMax: 90.p_evenNum: 3.p_oddNum: 3.p_filterNums: [4.7].p_checkNums: null,})Copy the code

The execution result