Last active
December 2, 2015 08:27
-
-
Save zekesonxx/6b4ef3ea415362aa9034 to your computer and use it in GitHub Desktop.
Node.js CLI sript to test the Triangle Inequality Theorem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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