aboutsummaryrefslogtreecommitdiff
path: root/samples/Perl/fib.pl
blob: 287ebf121990c731467198f8f3a53ca7d9c40bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! perl
# Copyright (C) 2001-2003, Parrot Foundation.

=head1 NAME

examples/benchmarks/fib.pl - Fibonacci Benchmark

=head1 SYNOPSIS

    % time perl examples/benchmarks/fib.pl n

=head1 DESCRIPTION

Calculates the Fibonacci Number for C<n> (defaults to 28 if
unspecified).

=cut

use strict;
use warnings;

sub fib {
    my $n = shift;
    return $n if ( $n < 2 );
    return fib( $n - 1 ) + fib( $n - 2 );
}
my $N = shift || 28;

print "fib($N) = ", fib($N), "\n";

=head1 SEE ALSO

F<examples/benchmarks/fib.pir>.

=cut

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4: