Hell Triangle Challenge for B2W - SkyHub
Node.js 4.3.2+
For a small triangle, it's possible to iterate over all lines and calculate all posible routes to return the highest value. However, using this technique in triangles with many lines, the number of possible routes could take a long time to be calculated or even overload the memory. The solution was to calculate the triangle bottom-up.
Install dependencies:
npm installBuild the library:
npm run buildNow create an js file and import the library:
constTriangle=require('./dist')Or using ES6:
importTrianglefrom'./dist'Initialize the library passing the matrix on its constructor, and calculates using the maxTotal method:
lettriangle=newTriangle([[6],[3,5],[9,7,1],[4,6,8,4]])console.log(triangle.maxTotal())To see this example in action run:
nodeexample.jsTo run the tests:
npm test- 0.1.0 Initial release