Sha256: 724e8cd2490c5cf46e11cf181d5aece93c45cc4bf8931df8c6fadbe6741d573e
Contents?: true
Size: 668 Bytes
Versions: 52
Compression:
Stored size: 668 Bytes
Contents
using System; using System.Linq; public class Squares { private readonly int max; public Squares(int max) { if (max < 0) { throw new ArgumentOutOfRangeException("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
52 entries across 52 versions & 1 rubygems