Skip to content

Instantly share code, notes, and snippets.

@gabrieljmj
Last active August 29, 2015 14:19
Show Gist options
  • Save gabrieljmj/eae18acbfb47126fa09d to your computer and use it in GitHub Desktop.
Save gabrieljmj/eae18acbfb47126fa09d to your computer and use it in GitHub Desktop.
Solving math problems
<?php
$end = false;
$initD = 0;
$S = 0;
while (!$end) {
$initD++;
$div = pow($initD, 2);
if (($initD % 2) === 0) {
$S += $initD / $div;
} else {
$S -= $initD / $div;
}
if ($initD == 10) {
$end = true;
}
}
echo $S;
<?php
$S = 0;
$x = 1;
for ($i = 1; $i < 50; $i++) {
$S += pow($x, $i) / $i;
}
echo $S;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment