Labs » Counsyl coding challenge

Summary

Find the path that finds the maximum output

Demo

Input
Output (sample tree)
Pot of Gold

Code

  
(function() {
  var generateData = function(level) {
    var last = [];
    while (level > 0) {
      var current = [];
      for (var i=0; i row[pointer]) {
          n = row[pointer + 1];
          pointer++;
        } else {
          n = row[pointer];
        }
      }
      sum += n;
      max.push(n);
    }
    return {
      'sum' : sum,
      'max' : max
    }
  }

  document.getElementById('start-demo').addEventListener('click', function(event) {
    event.preventDefault();

    var LEVELS = 8;
    
    var data = generateData(LEVELS);
    var triangle = renderTriangle(data);
    var calculated = parseData(data);
      
    document.getElementById('input').style.height = (LEVELS * 1.4).toString() + "em";
    document.getElementById('input').innerHTML = triangle;
    document.getElementById('output-max').innerHTML =  calculated.sum;
    document.getElementById('output-path').innerHTML = calculated.max.join(' » ');
  });
})();