Inital commit of prime factors goodie
parent
279d4e111f
commit
85e961be1d
|
@ -0,0 +1,26 @@
|
|||
package DDG::Goodie::PrimeFactors;
|
||||
#Returns all the prime factors of the entered number
|
||||
|
||||
use DDG::Goodie;
|
||||
use Math::Prime::Util 'factor';
|
||||
|
||||
zci answer_type => "prime_factors";
|
||||
zci is_cached => 1;
|
||||
|
||||
triggers startend => 'prime factors', 'prime factors of';
|
||||
|
||||
primary_example_queries 'prime factors of 30';
|
||||
secondary_example_queries '72 prime factors';
|
||||
description 'Returns the prime factors of the entered number';
|
||||
name 'PrimeFactors';
|
||||
topics 'math';
|
||||
category 'calculations';
|
||||
attribution github => [ 'https://github.com/austinheimark', 'austin_heimark' ];
|
||||
|
||||
handle remainder => sub {
|
||||
return unless /^\d+$/;
|
||||
my @factors = factor($_);
|
||||
return "Prime factors of $_: @factors";
|
||||
};
|
||||
|
||||
1;
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => "prime_factors";
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(
|
||||
DDG::Goodie::PrimeFactors
|
||||
)],
|
||||
'72 prime factors' => test_zci('Prime factors of 72: 2 2 2 3 3'),
|
||||
'prime factors of 111' => test_zci('Prime factors of 111: 3 37'),
|
||||
);
|
||||
|
||||
done_testing;
|
Loading…
Reference in New Issue