Skip to content

Instantly share code, notes, and snippets.

@davidkevork
Last active July 15, 2016 14:04
Show Gist options
  • Save davidkevork/fe57f5b2c778f9368ead3a9e8bfb8598 to your computer and use it in GitHub Desktop.
Save davidkevork/fe57f5b2c778f9368ead3a9e8bfb8598 to your computer and use it in GitHub Desktop.
<?php
/**
* lebgeeks.com register quiz solver
*
* @author David Kevork
*/
class LebGeeks
{
/**
* sum of $_i or $_j below $_below
* @var $_sum
*/
private $_sum = 0;
/**
* first number
* @var $_i
*/
private $_i = 0;
/**
* second number
* @var $_j
*/
private $_j = 0;
/**
* below number for sum
* @var $_below
*/
private $_below = 0;
/**
* set $_i, $_j, $_below
* @param integer $_i
* @param integer $_j
* @param integer $_below
* @return boolean
*/
public function __construct($_i = 0, $_j = 0, $_below = 0)
{
$this->_i = (int)$_i;
$this->_j = (int)$_j;
$this->_below = (int)$_below;
return true;
}
/**
* Set $_i
* @param integer $_i
* @return boolean
*/
public function Set_i($_i = 0)
{
$this->_i = (int)$_i;
return true;
}
/**
* Set $_j
* @param integer $_j
* @return boolean
*/
public function Set_j($_j = 0)
{
$this->_j = (int)$_j;
return true;
}
/**
* Set $_below
* @param integer $_below
* @return boolean
*/
public function Set_below($_below = 0)
{
$this->_below = (int)$_below;
return true;
}
/**
* Calculate Sum of $_i or $_j below $_below
* @return boolean
*/
public function CalcSum()
{
foreach(range(0, $this->_below) as $this->i) {
if($this->i % $this->_i == 0 || $this->i % $this->_j == 0) $this->_sum += $this->i;
}
return true;
}
/**
* Get $_i
* @return integer
*/
public function Get_i()
{
return $this->_i;
}
/**
* Get $_j
* @return integer
*/
public function Get_j()
{
return $this->_j;
}
/**
* Get $_below
* @return integer
*/
public function Get_below()
{
return $this->_below;
}
/**
* Get $_sum
* @return integer
*/
public function GetSum()
{
return $this->_sum;
}
}
// examples of how to use
// $LebGeeks = new LebGeeks($_i, $_j, $_below);
$LebGeeks = new LebGeeks(5, 17, 888);
$LebGeeks->CalcSum();
echo $LebGeeks->GetSum()."\n";
$i = $LebGeeks->Get_i();
$j = $LebGeeks->Get_j();
$below = $LebGeeks->Get_below();
$LebGeeks_1 = new LebGeeks;
$LebGeeks_1->Set_i($i);
$LebGeeks_1->Set_j($j);
$LebGeeks_1->Set_below($below );
$LebGeeks_1->CalcSum();
echo $LebGeeks_1->GetSum()."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment