Skip to main content

Posts

Advent of code 2022 day 21 part 1 in javascript

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