From 4950e8d574475e3aef0b236ecacf03d25cb30547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Kvist=20Aronsen?= Date: Fri, 21 Oct 2011 23:28:37 +0200 Subject: [PATCH] Added Golden Ratio Calculator goodie --- golden_ratio/goodie.pl | 24 ++++++++++++++++++++++++ golden_ratio/queries.txt | 14 ++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 golden_ratio/goodie.pl create mode 100644 golden_ratio/queries.txt diff --git a/golden_ratio/goodie.pl b/golden_ratio/goodie.pl new file mode 100755 index 000000000..dc29974e3 --- /dev/null +++ b/golden_ratio/goodie.pl @@ -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; +} + diff --git a/golden_ratio/queries.txt b/golden_ratio/queries.txt new file mode 100644 index 000000000..4cf8952a1 --- /dev/null +++ b/golden_ratio/queries.txt @@ -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