Added Golden Ratio Calculator goodie

master
André Kvist Aronsen 2011-10-21 23:28:37 +02:00
parent eba5637707
commit 4950e8d574
2 changed files with 38 additions and 0 deletions

24
golden_ratio/goodie.pl Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/perl
use strict;
# Calculates the Golden Ratio A:B given either A or B.
if ($q_check_lc =~ m/^golden ratio (?:(?:(\?)\s*:\s*(\d+(?:\.\d+)?))|(?:(\d+(?:\.\d+)?)\s*:\s*(\?)))$/i) {
my $golden_ratio = (1 + sqrt(5)) / 2;
my $result = 0;
if ($1 && $1 eq "?") {
# ? : x
$result = $2 / $golden_ratio;
$answer_results = "$result : $2";
} elsif ($4 && $4 eq "?") {
# x : ?
$result = $3 * $golden_ratio;
$answer_results = "$3 : $result";
}
$answer_type = "goldenratio";
$is_memcached = 1;
}

14
golden_ratio/queries.txt Normal file
View File

@ -0,0 +1,14 @@
golden ratio 1:?
golden ratio 2.5:?
golden ratio 450:?
golden ratio 900:?
golden ratio 1024.56:?
golden ratio ?:900
golden ratio ?:768.5
golden ratio ?:1680.12345678
golden ratio 1 : ?
golden ratio 1 :?
golden ratio 1: ?
golden ratio ? : 9
golden ratio ? :9
golden ratio ?: 9