Sha256: a136638e2497ececaaecd1b2b4f21dfc6629120834f942ed8dd859308e0986dd

Contents?: true

Size: 417 Bytes

Versions: 127

Compression:

Stored size: 417 Bytes

Contents

import "dart:math" show pow;

class DifferenceOfSquares {
  int squareOfSums(int input) => pow(_sum(input), 2);

  int sumOfSquares(int input) => _range(input).map((i) => pow(i, 2)).reduce((r, i) => r + i);

  int difference(int input) => squareOfSums(input) - sumOfSquares(input);

  int _sum(int input) => input * (input + 1) ~/ 2;

  List<int> _range(int length) => new List<int>.generate(length, (i) => i + 1);
}

Version data entries

127 entries across 127 versions & 1 rubygems

Version Path
trackler-2.2.1.113 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.111 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.110 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.109 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.108 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.107 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.106 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.105 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.104 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.103 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.102 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.101 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.100 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.99 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.98 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.97 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.96 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.95 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.94 tracks/dart/exercises/difference-of-squares/lib/example.dart
trackler-2.2.1.93 tracks/dart/exercises/difference-of-squares/lib/example.dart