Skip to content

Instantly share code, notes, and snippets.

@zekesonxx
Last active December 2, 2015 08:27
Show Gist options
  • Save zekesonxx/6b4ef3ea415362aa9034 to your computer and use it in GitHub Desktop.
Save zekesonxx/6b4ef3ea415362aa9034 to your computer and use it in GitHub Desktop.
Node.js CLI sript to test the Triangle Inequality Theorem
/**
* Short little Node.js command line script to test the Triangle Inequality Theorem
* Usage: node triangle.js sidea sideb sidec
* Copyright Zeke Sonxx 2015. Licensed under the MIT license <choosealicense.com/licenses/mit> (do whatever you want so long as you credit me)
*/
var a = parseInt(process.argv[2]);
var b = parseInt(process.argv[3]);
var c = parseInt(process.argv[4]);
console.log('Triangle with side lengths: %s, %s, and %s', a, b, c);
var ab = a + b > c;
var ac = a + c > b;
var cb = c + b > a;
console.log('%s + %s > %s: %s', a, b, c, ab);
console.log('%s + %s > %s: %s', a, c, b, ac);
console.log('%s + %s > %s: %s', c, b, a, cb);
console.log('conclusion: %s', (ab && ac && cb ? 'triangle' : 'not a triangle'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment