Sha256: 95c9ffae8d388366f211e42407550f644bd36af4461bc314a0f2b0521bdda169
Contents?: true
Size: 658 Bytes
Versions: 63
Compression:
Stored size: 658 Bytes
Contents
using System; using System.Linq; public class Squares { private readonly int max; public Squares(int max) { if (max < 0) { throw new ArgumentException("Max must be positive", "max"); } this.max = max; } public int SquareOfSums() { var numbers = Enumerable.Range(1, max); int sum = numbers.Sum(); return sum * sum; } public int SumOfSquares() { var numbers = Enumerable.Range(1, max); return numbers.Select(x => x * x).Sum(); } public int DifferenceOfSquares() { return SquareOfSums() - SumOfSquares(); } }
Version data entries
63 entries across 63 versions & 1 rubygems