2012-02-29 12:05:49 -08:00
|
|
|
package DDG::Goodie::GoldenRatio;
|
|
|
|
|
|
|
|
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-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;
|
|
|
|
my $result = 0;
|
|
|
|
|
|
|
|
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 "?") {
|
|
|
|
# x : ?
|
|
|
|
$result = $3 * $golden_ratio;
|
|
|
|
return "Golden ratio: $3 : $result";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
1;
|