2019/day 2/index.js
/**
 *
 * @param {string} inputFile The source file
 * @param {number} target The number to search for
 * @param {Function} cb The callback with resulting noun and verb
 */
@param {string} inputFile The source file
@param {number} target The number to search for
@param {Function} cb The callback with resulting noun and verb
@param { string } inputFile The source file @param { number } target The number to search for @param { Function } cb The callback with resulting noun and verb
function findInputsForTarget (inputFile, target, cb) {
  fs.readFile(inputFile, 'utf8', (err, data) => {
    if (err) cb(err)
    data = data.split(',').map(n => parseInt(n, 10))
    for (let noun = 0; noun < 100; noun++) {
      for (let verb = 0; verb < 100; verb++) {
        const copy = Object.assign([], data)
        copy[1] = noun
        copy[2] = verb
        const intcode = makeIntcode(copy)[0]
        if (intcode === target) {
          cb(null, [noun, verb])
          return
        }
      }
    }
    cb(new Error('No input possible'))
  })
}
function findInputsForTarget ( inputFile , target , cb ) { fs . readFile ( inputFile , 'utf8' , ( err , data ) => { if ( err ) cb ( err ) data = data . split ( ',' ) . map ( n => parseInt ( n , 10 ) ) for ( let noun = 0 ; noun < 100 ; noun ++ ) { for ( let verb = 0 ; verb < 100 ; verb ++ ) { const copy = Object . assign ( [ ] , data ) copy [ 1 ] = noun copy [ 2 ] = verb const intcode = makeIntcode ( copy ) [ 0 ] if ( intcode === target ) { cb ( null , [ noun , verb ] ) return } } } cb ( new Error ( 'No input possible' ) ) } ) }
@param {string} inputFile The source file
 @param {number} target The number to search for
 @param {Function} cb The callback with resulting noun and verb
@param { string } inputFile The source file @param { number } target The number to search for @param { Function } cb The callback with resulting noun and verb