Sha256: 7e00e2b285839a3439b2d84a6b636551019d59a7b192805d08261fdbaf8214b3

Contents?: true

Size: 362 Bytes

Versions: 73

Compression:

Stored size: 362 Bytes

Contents

package Prime;
use strict;
use warnings;

sub factors {
    my ($num) = @_;

	return [] if $num == 1;
    my @factors;
    my $i = 2;
	while ($i*$i <= $num) {
		my $div = $num/$i;
	    if ($div == int $div) {
            push @factors, $i;
            $num = $div;
            next;
        }
        $i++;
	}
	push @factors, $num;

    return \@factors;
}

1;

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.118 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.117 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.116 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.115 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.114 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.113 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.111 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.110 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.109 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.108 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.107 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm
trackler-2.2.1.106 tracks/perl5/exercises/prime-factors/.meta/solutions/Prime.pm