Sha256: 3c03fbb922245899d8354603b382f00233725346487e518992d1a63c734ae5ed

Contents?: true

Size: 661 Bytes

Versions: 323

Compression:

Stored size: 661 Bytes

Contents

package Example;

use strict;
use warnings;
use 5.010; # use smart_match ~~

sub triangle {
    my $size = shift;
    my @rows = ([1],);

    foreach my $i (1..$size) {
       my ($prev, $next) = $rows[$i-1];
       for my $j (0..@$prev) {
           $next->[$j] += $prev->[$j-1] if $j > 0;
           $next->[$j] += $prev->[$j]   if $j < @$prev;
       }
       push @rows => $next;
    }
    return [ map { join q{ } => @$_ } @rows ];
}

sub is_triangle {
    my $aaa = shift;
    my $bbb = triangle(@$aaa-1);

    return int(@$aaa ~~ @$bbb); # JSON::true is 1 JSON::false is 0
}

sub row {
    my $n = shift;
    return (triangle($n))->[$n];
}

__PACKAGE__;

Version data entries

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.104 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.103 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.102 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.101 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.100 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.99 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.98 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.97 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.96 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.95 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.94 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.93 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.92 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.91 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.90 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.89 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.88 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.87 tracks/perl5/exercises/pascals-triangle/Example.pm
trackler-2.2.1.86 tracks/perl5/exercises/pascals-triangle/Example.pm