2012-02-29 12:05:49 -08:00
|
|
|
package DDG::Goodie::GoldenRatio;
|
2014-08-20 11:45:33 -07:00
|
|
|
# ABSTRACT: find number related to the given number by the Golden Ratio.
|
2012-02-29 12:05:49 -08:00
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2012-02-29 12:05:49 -08:00
|
|
|
use DDG::Goodie;
|
|
|
|
|
|
|
|
zci answer_type => "golden_ratio";
|
|
|
|
|
|
|
|
zci is_cached => 1;
|
|
|
|
|
2012-05-23 19:05:08 -07:00
|
|
|
triggers start => "golden ratio";
|
2012-02-29 12:05:49 -08:00
|
|
|
|
2012-11-06 14:37:55 -08:00
|
|
|
primary_example_queries 'golden ratio 900:?';
|
|
|
|
secondary_example_queries 'golden ratio ?:123.345';
|
|
|
|
description 'find the number in the golden ratio with a number';
|
|
|
|
name 'GoldenRatio';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/GoldenRatio.pm';
|
|
|
|
category 'calculations';
|
|
|
|
topics 'math';
|
2015-01-07 10:37:42 -08:00
|
|
|
attribution twitter => ['crazedpsyc','crazedpsyc'],
|
|
|
|
cpan => ['CRZEDPSYC','crazedpsyc'];
|
2012-11-06 14:37:55 -08:00
|
|
|
|
2012-05-23 19:05:08 -07:00
|
|
|
handle remainder => sub {
|
|
|
|
my $input = $_;
|
2012-02-29 12:05:49 -08:00
|
|
|
my $golden_ratio = (1 + sqrt(5)) / 2;
|
2014-10-28 11:36:15 -07:00
|
|
|
my $result = 0;
|
2012-02-29 12:05:49 -08:00
|
|
|
|
|
|
|
if ($input =~ /^(?:(?:(\?)\s*:\s*(\d+(?:\.\d+)?))|(?:(\d+(?:\.\d+)?)\s*:\s*(\?)))$/) {
|
|
|
|
if ($1 && $1 eq "?") {
|
|
|
|
# ? : x
|
|
|
|
$result = $2 / $golden_ratio;
|
|
|
|
return "Golden ratio: $result : $2";
|
|
|
|
} elsif ($4 && $4 eq "?") {
|
2014-10-28 11:36:15 -07:00
|
|
|
# x : ?
|
|
|
|
$result = $3 * $golden_ratio;
|
2012-02-29 12:05:49 -08:00
|
|
|
return "Golden ratio: $3 : $result";
|
2014-10-28 11:36:15 -07:00
|
|
|
}
|
2012-02-29 12:05:49 -08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
1;
|