Sha256: eb5868c90c941253417d179244c61066c0872296d196f91e01784879ebf97b01

Contents?: true

Size: 428 Bytes

Versions: 323

Compression:

Stored size: 428 Bytes

Contents

package Example;

use strict;
use warnings;

use List::Util 'sum';

sub new {
    my ($class, $to) = @_;
    return bless { to => $to }, $class;
}

sub sum_of_squares {
    my $self = shift;
    return sum map { $_ ** 2 } 1..$self->{to};
}

sub square_of_sums {
    my $self = shift;
    return (sum 1..$self->{to}) ** 2;
}

sub difference {
    my $self = shift;
    return $self->square_of_sums - $self->sum_of_squares;
}

1;

Version data entries

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.25 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.24 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.23 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.22 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.21 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.20 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.19 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.18 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.17 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.16 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.15 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.14 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.13 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.12 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.11 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.10 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.9 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.8 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.7 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.6 tracks/perl5/exercises/difference-of-squares/Example.pm