Learning Dart
This commit is contained in:
21
dart/difference-of-squares/lib/difference_of_squares.dart
Normal file
21
dart/difference-of-squares/lib/difference_of_squares.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'dart:math' show pow;
|
||||
|
||||
class DifferenceOfSquares {
|
||||
int squareOfSum(int v) {
|
||||
int total = 0;
|
||||
for(int i = 1; i <= v; i++) {
|
||||
total += i;
|
||||
}
|
||||
return pow(total, 2) as int;
|
||||
}
|
||||
|
||||
int sumOfSquares(int v) {
|
||||
int total = 0;
|
||||
for(int i = 1; i <= v; i++) {
|
||||
total += pow(i, 2) as int;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
int differenceOfSquares(int v) => squareOfSum(v) - sumOfSquares(v);
|
||||
}
|
Reference in New Issue
Block a user