How to use:
node pen.js width height pennies_per_stack pennies_removed_per_row
"use strict"; // perfromance optimization | |
var num_width = process.argv[2]; | |
var num_height = process.argv[3]; | |
var num_stack = process.argv[4]; | |
var num_dec = process.argv[5]; | |
console.log('h:', num_height, 'w:', num_width, 'dec:', num_dec, 'stack:', num_stack); | |
if(!num_stack || !num_width || !num_height || !num_dec) { | |
console.log('invalid input'); | |
process.exit(1); // bad error code | |
} | |
// scope & instancing | |
var num = 0, | |
total = 0; | |
console.time('main'); | |
for(var i = 0; num !== 1; i++) { | |
var nd_wi = num_dec*i; // calculate amount to subtract from difference * iteration | |
var nh_wd = num_height-nd_wi; // calculate the height with difference | |
var nw_wd = num_width-nd_wi; // calculate the width with difference | |
var num = nw_wd*nh_wd; // get the area based on width and height | |
var num_ws = num*num_stack // get the amount w/ the variable stack. | |
total += num_ws; // add that layer to the total. | |
} | |
console.log('total is', total); | |
console.timeEnd('main'); |