first commit
This commit is contained in:
27
perl/Examples/Chap5/fib-5
Normal file
27
perl/Examples/Chap5/fib-5
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
###
|
||||
### fib5
|
||||
###
|
||||
|
||||
## Chapter 5 section 4.3.1
|
||||
|
||||
sub fib {
|
||||
my $n = shift;
|
||||
my ($s1, $s2, $return);
|
||||
my $BRANCH = 0;
|
||||
while (1) {
|
||||
if ($n < 2) {
|
||||
$return = $n;
|
||||
} else {
|
||||
if ($BRANCH == 0) {
|
||||
$return = fib($n-2);
|
||||
} elsif ($BRANCH == 1) {
|
||||
$s1 = $return;
|
||||
$return = fib($n-1);
|
||||
} elsif ($BRANCH == 2) {
|
||||
$return = $s1 + $s2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user