Sha256: 9a319004892192b9faadf9cba9ec672c941a051a3f58590edfe9161799bf4b07

Contents?: true

Size: 527 Bytes

Versions: 181

Compression:

Stored size: 527 Bytes

Contents

module difference_of_squares;

import std.range : iota;
import std.algorithm : sum, map;

struct Squares {
    this(uint max) pure {
        end = max + 1;
    }

    @property uint squareOfSum() const pure {
        return iota(end).sum ^^ 2;
    }

    @property uint sumOfSquares() const pure {
        return iota(end).map!"a ^^ 2".sum;
    }

    @property uint difference() const pure {
        return squareOfSum - sumOfSquares;
    }
    private uint end;
}

Squares squares(uint max) pure {
    return Squares(max);
}

Version data entries

181 entries across 181 versions & 1 rubygems

Version Path
trackler-2.0.6.25 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.24 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.23 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.22 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.21 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.20 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.19 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.18 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.17 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.16 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.15 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.14 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.13 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.12 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.11 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.10 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.9 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.8 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.7 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d
trackler-2.0.6.6 tracks/dlang/exercises/difference-of-squares/difference_of_squares_example.d