From 8474384ca8dff0ceab70b4a09ee9402d7fd04b5c Mon Sep 17 00:00:00 2001 From: mhunsinger Date: Tue, 21 Jun 2016 05:52:02 +0000 Subject: [PATCH] Changed response to strings, was hanging on large Fibonacci. --- lib/DDG/Goodie/Fibonacci.pm | 11 ++++------- t/Fibonacci.t | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/DDG/Goodie/Fibonacci.pm b/lib/DDG/Goodie/Fibonacci.pm index 058c7a69a..137cac013 100755 --- a/lib/DDG/Goodie/Fibonacci.pm +++ b/lib/DDG/Goodie/Fibonacci.pm @@ -6,6 +6,7 @@ use strict; use DDG::Goodie; use Lingua::EN::Numbers::Ordinate qw(ordsuf); use Math::NumSeq::Fibonacci; +use Math::BigInt; triggers any => 'fib', 'fibonacci'; @@ -17,8 +18,8 @@ sub answer { return $text_ans, structured_answer => { data => { - title => $title, - subtitle => $subtitle + title => "$title", + subtitle => "$subtitle" }, templates => { group => 'text' @@ -31,10 +32,6 @@ my $pred_limit = 10**22; # limit for if n is a fibonacci number my $fib_seq = Math::NumSeq::Fibonacci->new; handle remainder_lc => sub { - # # trim whitespace around remainder - # s/^\s+//; - # s/\s+$//; - # check "what is the nth fibonacci number" if (/^(?:what(?:'s| is) the )?(?\d+)(?:st|nd|rd|th)?(?: number)?(?: in the (?:series|sequence))?\??$/ && $1 <= $ith_limit) { @@ -43,7 +40,7 @@ handle remainder_lc => sub { my $suf = ordsuf($n); my $text_answer ="The $n$suf fibonacci number is $val (assuming f(0) = 0)"; - return answer($text_answer, $val, "$n$suf Fibonacci number"); + return answer($text_answer, $val, "$n$suf Fibonacci number"); } # check "is n a fibonacci number" elsif (/^is (?\d+) (?:a|in the)? ?(?:number|sequence)?\??$/ && $1 <= $pred_limit) diff --git a/t/Fibonacci.t b/t/Fibonacci.t index 573e7176f..60e655044 100755 --- a/t/Fibonacci.t +++ b/t/Fibonacci.t @@ -14,8 +14,8 @@ sub build_structured_answer { return $text_answer, structured_answer => { data => { - title => $title, - subtitle => $subtitle + title => "$title", + subtitle => "$subtitle" }, templates => { group => 'text'