* * @return int Difference between the sum of the squares and * the square of the sum * * @link https://projecteuler.net/problem=6 */ /** * @param int $maxNumber Range from 1 to * * @return int Difference between the sum of the squares and * the square of the sum */ function problem6(int $maxNumber = 100): int { $sumOfSquares = 0; $sums = 0; for ($i = 1; $i <= $maxNumber; $i++) { $sumOfSquares += $i ** 2; // add squares to the sum of squares $sums += $i; // add number to sum to square later } return ($sums ** 2) - $sumOfSquares; // difference of square of the total sum and sum of squares }