accept "what is the __ fibonacci number" syntax

master
Dylan Lloyd 2013-01-24 05:18:01 -05:00
parent a710e6b4b0
commit 6d49bb5c11
1 changed files with 4 additions and 4 deletions

View File

@ -20,9 +20,9 @@ topics 'math';
handle remainder => sub { handle remainder => sub {
s/^\s+//; s/^\s+//;
s/\s+$//; s/\s+$//;
return unless /^\d+$/ && $_ <= 1470; return unless /^(?:what is the )?(\d+)(?:(?:th|rd|st)? number\??)?$/ && $1 <= 1470;
my @fib; my @fib;
$#fib = $_; $#fib = $1;
$fib[0] = 0; $fib[0] = 0;
$fib[1] = 1; $fib[1] = 1;
# Instead of calling a typical recursive function, # Instead of calling a typical recursive function,
@ -31,8 +31,8 @@ handle remainder => sub {
$fib[$i] = $fib[$i - 1] + $fib[$i - 2]; $fib[$i] = $fib[$i - 1] + $fib[$i - 2];
} }
my $suf = ordsuf($_); my $suf = ordsuf($_);
return "The $_$suf fibonacci number is ${fib[$_]} (assuming f(0) = 0).", return "The $1$suf fibonacci number is ${fib[$1]} (assuming f(0) = 0).",
html => "The $_<sup>$suf</sup> fibonacci number is ${fib[$_]} (assuming f(0) = 0)."; html => "The $1<sup>$suf</sup> fibonacci number is ${fib[$1]} (assuming f(0) = 0).";
}; };
1; 1;