Created
May 14, 2012 08:23
-
-
Save suzuken/2692683 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* 三角形の判定 | |
*/ | |
function triangle($a, $b, $c){ | |
if (!isValid($a) || !isValid($b) || !isValid($c)){ | |
return false; | |
} | |
if (!isTriangle($a, $b, $c)) { | |
return false; | |
} | |
if (isEquilateral($a, $b, $c)) { | |
return 'equilateral'; | |
} | |
elseif (isIsosceles($a, $b, $c)) { | |
return 'isosceles'; | |
} | |
else { | |
return 'scalene'; | |
} | |
} | |
function isEquilateral($a, $b, $c) | |
{ | |
if ($a === $b && $b===$c && $c===$a) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
function isIsosceles($a, $b, $c) | |
{ | |
if ($a===$b || $b===$c || $c===$a) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
/** | |
* isValid | |
* | |
* 辺の値は有効かどうか | |
* | |
* @param string $a | |
* @access public | |
* @return void | |
*/ | |
function isValid($site) | |
{ | |
if (!is_int($site)) | |
return false; | |
if ($site < 1 || $site > 100) | |
return false; | |
return true; | |
} | |
/** | |
* isTriangle | |
* | |
* 辺の和及び差は正しいかどうか | |
* | |
* @param string $a | |
* @param string $b | |
* @param string $c | |
* @access public | |
* @return void | |
*/ | |
function isTriangle($a, $b, $c) | |
{ | |
if ( | |
($a < $b + $c) | |
&& ($b<$c + $a) | |
&& ($c<$a + $b) | |
) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment