Skip to content

Instantly share code, notes, and snippets.

@ryokwkm
Last active July 25, 2017 06:16
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 ryokwkm/e6a6ff2bd623e961929c874fa8aa1e5e to your computer and use it in GitHub Desktop.
Save ryokwkm/e6a6ff2bd623e961929c874fa8aa1e5e to your computer and use it in GitHub Desktop.
<?php
// Here your code !
$originCode = array(3, 5, 7);
$testNumber = array( 3, 5 );
$testNumberIndex = array(0, 0);
$testNumberAnswer = array();
$test = new matrixCalc();
$answerArray = array();
for($i=0; $i <= 7; $i++ ) {
$answerArrayTmp = $test->matrix($i);
echo $i . ": ";
simpleEcho($answerArrayTmp);
$answerArray = array_merge($answerArray,$answerArrayTmp);
}
sort($answerArray);
simpleEcho( $answerArray );
class matrixCalc {
protected $targetNumber = array(3, 5);
function __construct($targetDefault=null) {
if( $targetDefault != null ) {
self::$targetDefault = $targetDefault;
}
}
function matrix($max) {
$matrixAnswerList = array();
$testNumberIndex = array($max, 0);
for($i=$max; $i >= 0; $i-- ) {
//simpleEcho($testNumberIndex);
$matrixAnswerList[] = $this->powCalc($testNumberIndex);
$testNumberIndex[0]--;
$testNumberIndex[1]++;
}
return $matrixAnswerList;
}
function powCalc($calcArray) {
$answerArray = array();
$answerArray[0] = $this->targetNumber[0] ** $calcArray[0];
$answerArray[1] = $this->targetNumber[1] ** $calcArray[1];
return $answerArray[0] * $answerArray[1];
}
}
function simpleEcho( $array ) {
foreach($array as $value ) {
echo $value. ", ";
}
echo "\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment