Skip to content

Instantly share code, notes, and snippets.

@suzuken
Created May 14, 2012 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzuken/2692683 to your computer and use it in GitHub Desktop.
Save suzuken/2692683 to your computer and use it in GitHub Desktop.
<?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