Created
April 30, 2020 12:55
-
-
Save CITGuru/907da53083f7229bd0312f83d721f340 to your computer and use it in GitHub Desktop.
This file contains 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
function nebsochiSolution($n) | |
{ | |
$squares = $n == 1 ? 1 : ($n == 0 ? null : pow(floor(sqrt($n)), 2).','.nebsochiSolution($n - pow(floor(sqrt($n)), 2))); | |
return rtrim($squares,','); | |
} | |
function SetThingsStraight($No){ | |
$Results = []; | |
for($i = 1; $i <= $No; $i++){ | |
$p = $i * $i; | |
$e = ($i-1)*($i-1); | |
if($p == $No){ | |
array_push($Results, $No); | |
break; | |
}else if($p > $No){ | |
array_push($Results, $e); | |
$No -= $e; | |
$i = 0; | |
}else if($No == 1){ | |
array_push($Results, $No); | |
break; | |
} | |
} | |
print_r($Results); | |
} | |
$start = microtime(TRUE); | |
echo "Nebsochi"; | |
echo "<br/>"; | |
echo nebsochiSolution(15324); | |
echo "<br/>"; | |
echo nebsochiSolution(12); | |
echo "<br/>"; | |
echo nebsochiSolution(2982); | |
echo "<br/>"; | |
echo nebsochiSolution(9); | |
echo "<br/>"; | |
$end = microtime(TRUE); | |
echo "Nebsochi code took " . ($end - $start) . " seconds to complete."; | |
echo "<br/>"; | |
$start2 = microtime(TRUE); | |
echo "NabStacks1"; | |
echo "<br/>"; | |
echo SetThingsStraight(15324); | |
echo "<br/>"; | |
echo SetThingsStraight(12); | |
echo "<br/>"; | |
echo SetThingsStraight(2982); | |
echo "<br/>"; | |
echo SetThingsStraight(9); | |
echo "<br/>"; | |
$end2 = microtime(TRUE); | |
echo "NabStacks1 code took " . ($end2 - $start2) . " seconds to complete."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment