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.85 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.84 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.83 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.82 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.81 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.80 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.79 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.78 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.77 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.76 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.75 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.74 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.73 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.72 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.71 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.70 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.69 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.68 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.67 tracks/perl5/exercises/difference-of-squares/Example.pm
trackler-2.2.1.66 tracks/perl5/exercises/difference-of-squares/Example.pm