Created
April 29, 2020 21:26
-
-
Save gavinsykes/ab54bdbcd69e8c4f60ad55f7263f9129 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
function euler_6($n) { | |
if ($n < 1 || !is_int($n)) { | |
return undefined; | |
} | |
$result = 0; | |
$sumsquares = 0; | |
$sum = 0; | |
$squaresum = 0; | |
for ($i = 1; $i <= $n; $i++) { | |
$sumsquares += $i**2; | |
} | |
for ($i = 1; $i <= $n; $i++) { | |
$sum += $i; | |
} | |
$squaresum = $sum**2; | |
$result = $squaresum - $sumsquares; | |
return $result; | |
} | |
$v = $_REQUEST['val']; | |
echo euler_6($v); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment