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

Version Path
trackler-2.0.6.7 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.6 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.5 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.4 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.3 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.2 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.1 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.6.0 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.18 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.17 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.16 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.15 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.14 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.13 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.12 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.11 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.10 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.9 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.8 tracks/csharp/exercises/difference-of-squares/Example.cs
trackler-2.0.5.7 tracks/csharp/exercises/difference-of-squares/Example.cs