Sha256: 429794639ce4a338a751f566f61a3fe0c6242bb2e7cb811f0b4ad875d9986aee
Contents?: true
Size: 1010 Bytes
Versions: 384
Compression:
Stored size: 1010 Bytes
Contents
<?php class Triangle { protected $sideA; protected $sideB; protected $sideC; public function __construct($sideA, $sideB, $sideC) { $this->sideA = $sideA; $this->sideB = $sideB; $this->sideC = $sideC; } public function kind() { if (0 == ($this->sideA + $this->sideB + $this->sideC)) { throw new \Exception("These sides have no values."); } $sides = [$this->sideA, $this->sideB, $this->sideC]; sort($sides); if ($sides[2] >= $sides[0] + $sides[1]) { throw new \Exception("This violates the triangle inequality"); } if ($this->sideA == $this->sideB && $this->sideA == $this->sideC ) { return 'equilateral'; } if ($this->sideB == $this->sideC || $this->sideA == $this->sideC || $this->sideA == $this->sideB ) { return 'isosceles'; } return 'scalene'; } }
Version data entries
384 entries across 384 versions & 1 rubygems