Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,9 +1,32 @@
sub fibIter {
my $n = shift;
return $n if $n < 2;
# Iterative Fibonacci with bignum support.
# Multi-licensed under your choice of:
# 1. The GNU Free Documentation License (GFDL).
# 2. The MIT/X11 license.
# 3. The GNU General Publice License (GPL).
# 4. The Public Domain as understood by the CC-Zero public domain dedication.
my $fibPrev = 1;
my $fib = 1;
($fibPrev, $fib) = ($fib, $fib + $fibPrev) for 2..$n-1;
$fib;
use strict;
use warnings;
use Math::BigInt try => 'GMP';
sub fib_iter
{
my ($n) = @_;
my $this_fib = Math::BigInt->new(0);
my $next_fib = Math::BigInt->new(1);
my $pos = 0;
while ($pos < $n)
{
($this_fib, $next_fib) = ($next_fib, $this_fib+$next_fib);
}
continue
{
$pos++;
}
return $this_fib;
}