recurse.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
#
# test recursive functions.
#
print "1..25\n";
$_[0];
}
}
}
# Highly recursive, highly aggressive.
# Kids, don't try this at home.
#
# For example ackermann(4,1) will take quite a long time.
# It will simply eat away your memory. Trust me.
return $_[1] + 1 if ($_[0] == 0);
}
# Highly recursive, highly boring.
$_[1] < $_[0] ?
: $_[2];
}
print "ok 1\n";
print "# gcd(1147, 1271) = $d\n";
print "ok 2\n";
print "# gcd(1908, 2016) = $d\n";
print "ok 3\n";
print "# factorial(10) = $f\n";
print "ok 4\n";
print "# factorial(factorial(3)) = $f\n";
print "ok 5\n";
print "# fibonacci(10) = $f\n";
print "ok 6\n";
print "# fibonacci(fibonacci(7)) = $f\n";
$i = 7;
for $x (0..3) {
for $y (0..3) {
print "ok ", $i++, "\n";
print "# ackermann($x, $y) = $a\n";
}
}
($x, $y, $z) = (18, 12, 6);
print "ok ", $i++, "\n";
print "# takeuchi($x, $y, $z) = $t\n";
{
sub get_first1 {
}
sub get_list1 {
return [24] unless $_[0];
[$u];
}
print "ok $x\n";
}
{
sub get_first2 {
}
sub get_list2 {
return [25] unless $_[0];
return [$u];
}
print "ok $x\n";
}
$i = 26;