Skip to main content

Posts

Showing posts from December, 2022

Advent of code 2022 day 22 part 1

  function main(input, input1) {     let grid = input.split( '\n' );     grid.shift();     // only in big input     for ( let i = 0 ; i < 100 ; i++) {         grid[i] = '                                                  ' + grid[i];     }     //console.log(grid[100])     grid = grid.map(x => x.split( '' ))     // find first left top allowed     let temppos = - 1 ;     grid[ 0 ].forEach((element, i) => {         if (temppos == - 1 && element == '.' ) {             temppos = i;         }     });     let initpos = new pos(temppos, 0 )     // console.log(initpos)     // make grid equal shape     let maxlength = 0 ;     grid.forEach(el => {         if (el.length > maxlength) {             maxlength = el.length         }     })     console.log(maxlength)     grid.forEach(el => {         if (el.length < maxlength) {             let diff = maxlength - el.length;             while (diff > 0 ) {                 di

Advent of code 2022 day 21 part 2 javascript solution

  function solve1 ( input ) {     let obj = {};     input . split ( ' \n ' ). forEach ( el => {         obj [ el . split ( ': ' )[ 0 ]] = el . split ( ': ' )[ 1 ]     });     console . log ( obj )     let t = obj [ 'root' ]. split ( ' ' );     let first = t [ 0 ];     let second = t [ 2 ];     console . log ( find_humn ( first , obj , false ))     console . log ( find_humn ( second , obj , false ))     let solved_one_half = find_humn ( first , obj , false ) == true ?         solve ( second , obj ) : solve ( first , obj );     console . log ( solved_one_half )     console . log ( solve ( first , obj )*- 1 )     let result = find_humn_value ( obj , solved_one_half *- 1 , find_humn ( first , obj , false ) == true ?         first : second )     return result ; } function find_humn ( node , obj , value ) {     if ( value ) return value ;     if ( isNaN ( obj [ node ]. trim ())) // not a number,,solve again     {         let