Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created April 29, 2020 21:26
Show Gist options
  • Save gavinsykes/ab54bdbcd69e8c4f60ad55f7263f9129 to your computer and use it in GitHub Desktop.
Save gavinsykes/ab54bdbcd69e8c4f60ad55f7263f9129 to your computer and use it in GitHub Desktop.
<?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