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.105 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.104 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.103 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.102 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.101 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.100 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.99 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.98 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.97 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.96 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.95 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.94 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.93 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.92 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.91 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.90 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.89 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.88 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.87 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.86 tracks/perl5/exercises/difference-of-squares/Example.pm