Created
December 1, 2011 23:47
-
-
Save freddiefujiwara/1420760 to your computer and use it in GitHub Desktop.
Triangable max
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
var isTriangable = function(a,b,c){ | |
var max = Math.max.apply(null,[a,b,c]); | |
var tmp = $([a,b,c]).filter(function(i,v){ | |
return v != max; | |
}); | |
if(2 != tmp.length){ | |
return true; | |
} | |
return max < (tmp[0] + tmp[1]); | |
}; | |
var input = [2,3,4,5,10]; | |
var totals = []; | |
for(var i = 0; i < input.length ; i ++){ | |
for(var j = i+1 ; j < input.length ; j++){ | |
for(var k = j + 1 ; k < input.length ; k ++){ | |
if(isTriangable(input[i],input[j],input[k])){ | |
totals.push(input[i]+input[j]+input[k]); | |
} | |
} | |
} | |
} | |
console.log(Math.max.apply(null,totals)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python version.