Created
June 16, 2019 19:07
-
-
Save westdabestdb/ba765e28e29da66420af55f244e361ea to your computer and use it in GitHub Desktop.
DifferenceOfSquares
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
import 'dart:math'; | |
void main() { | |
var d = DifferenceOfSquares(); | |
var sum = d.differenceOfSquares(10); | |
print(sum); | |
} | |
class DifferenceOfSquares { | |
int sumOfSquares(int inputInt) => List<int>.generate(inputInt, (i) => i + 1) | |
.map((x) => x * x) | |
.reduce((a, b) => a + b); | |
int squareOfSum(int inputInt) => pow( | |
List<int>.generate(inputInt, (i) => i + 1).reduce((a, b) => a + b), 2); | |
int differenceOfSquares(int inputInt) => | |
squareOfSum(inputInt) - sumOfSquares(inputInt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment