Inital commit of prime factors goodie

master
austinheimark 2013-05-15 11:15:50 -04:00
parent 279d4e111f
commit 85e961be1d
2 changed files with 45 additions and 0 deletions

View File

@ -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;

19
t/PrimeFactors.t Normal file
View File

@ -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;