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

Version Path
trackler-2.0.8.14 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.13 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.12 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.11 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.10 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.9 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.8 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.7 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.6 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.5 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.4 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.3 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.2 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.8.1 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.7.0 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.44 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.43 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.42 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.41 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.40 tracks/csharp/exercises/difference-of-squares/Example.cs