advent25_stars.js
/**
     * @param evidenceRequirement max executions to perform
     * @param searchLimit maximum register 'a' value to try
     */
@param evidenceRequirement max executions to perform
@param searchLimit maximum register 'a' value to try
@param evidenceRequirement max executions to perform @param searchLimit maximum register ' a ' value to try
function findSignal(instructions, evidenceRequirement, initialRegisterA, collectSignal, searchLimit) {
        initialRegisterA = initialRegisterA || 0;
        searchLimit = searchLimit || -1;
        while (searchLimit < 0 || initialRegisterA < searchLimit) {
            var registers = createRegisters();
            initialRegisterA++;
            registers['a'] = initialRegisterA;
            if (initialRegisterA > 0 && initialRegisterA % 1000 === 0) {
                console.error("tried with initial register a value of " + initialRegisterA.toString());
            }
            var processor = new Processor(registers, logger);
            var signal = [];
            function SignalChecker() {
                var previous = 1;
                var clean;
                this.callback = (() => function(x) {
                    if (collectSignal) {
                        signal.push(x);
                    }
                    if (x !== 0 && x !== 1) {
                        return clean = false;
                    }
                    if (previous === 1 && x !== 0) {
                        return clean = false;
                    }
                    if (previous === 0 && x !== 1) {
                        return clean = false;
                    }
                    previous = x;
                    return clean = true;
                });
                this.isClean = (() => clean);
            }
            var signalChecker = new SignalChecker();
            var callback = signalChecker.callback();
            processor.process(instructions, evidenceRequirement, callback);
            if (signalChecker.isClean()) {
                console.log("clean execution with initial register a value", initialRegisterA);
                if (collectSignal) {
                    console.log("signal", signal.slice(0, 10));
                }
                return initialRegisterA;
            }
        }
        if (initialRegisterA >= searchLimit) {
            console.error("reached search limit " + searchLimit);
            return false;
        }
        throw 'illegal state';
    }
function findSignal ( instructions , evidenceRequirement , initialRegisterA , collectSignal , searchLimit ) { initialRegisterA = initialRegisterA || 0 ; searchLimit = searchLimit || - 1 ; while ( searchLimit < 0 || initialRegisterA < searchLimit ) { var registers = createRegisters ( ) ; initialRegisterA ++ ; registers [ 'a' ] = initialRegisterA ; if ( initialRegisterA > 0 && initialRegisterA % 1000 === 0 ) { console . error ( "tried with initial register a value of " + initialRegisterA . toString ( ) ) ; } var processor = new Processor ( registers , logger ) ; var signal = [ ] ; function SignalChecker ( ) { var previous = 1 ; var clean ; this . callback = ( ( ) => function ( x ) { if ( collectSignal ) { signal . push ( x ) ; } if ( x !== 0 && x !== 1 ) { return clean = false ; } if ( previous === 1 && x !== 0 ) { return clean = false ; } if ( previous === 0 && x !== 1 ) { return clean = false ; } previous = x ; return clean = true ; } ) ; this . isClean = ( ( ) => clean ) ; } var signalChecker = new SignalChecker ( ) ; var callback = signalChecker . callback ( ) ; processor . process ( instructions , evidenceRequirement , callback ) ; if ( signalChecker . isClean ( ) ) { console . log ( "clean execution with initial register a value" , initialRegisterA ) ; if ( collectSignal ) { console . log ( "signal" , signal . slice ( 0 , 10 ) ) ; } return initialRegisterA ; } } if ( initialRegisterA >= searchLimit ) { console . error ( "reached search limit " + searchLimit ) ; return false ; } throw 'illegal state' ; }
@param evidenceRequirement max executions to perform
 @param searchLimit maximum register 'a' value to try
@param evidenceRequirement max executions to perform @param searchLimit maximum register ' a ' value to try