Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,32 +1,7 @@
|
|||
# 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.
|
||||
|
||||
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;
|
||||
sub fib_iter {
|
||||
my $n = shift;
|
||||
use bigint try => "GMP,Pari";
|
||||
my ($v2,$v1) = (-1,1);
|
||||
($v2,$v1) = ($v1,$v2+$v1) for 0..$n;
|
||||
$v1;
|
||||
}
|
||||
|
|
|
|||
20
Task/Fibonacci-sequence/Perl/fibonacci-sequence-3.pl
Normal file
20
Task/Fibonacci-sequence/Perl/fibonacci-sequence-3.pl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Binary ladder, GMP if available, Pure Perl otherwise
|
||||
use ntheory qw/lucasu/;
|
||||
say lucasu(1, -1, 10000);
|
||||
|
||||
# Uses GMP internal method, so similar performance as above
|
||||
use Math::GMP;
|
||||
say Math::GMP::fibonacci(10000);
|
||||
|
||||
# All Perl
|
||||
use Math::NumSeq::Fibonacci;
|
||||
my $seq = Math::NumSeq::Fibonacci->new;
|
||||
say $seq->ith(10000);
|
||||
|
||||
# All Perl
|
||||
use Math::Big qw/fibonacci/;
|
||||
say 0+fibonacci(10000); # Force scalar context
|
||||
|
||||
# Perl, gives floating point *approximation*
|
||||
use Math::Fibonacci qw/term/;
|
||||
say term(10000);
|
||||
Loading…
Add table
Add a link
Reference in a new issue