LoginSignup
1
1

More than 5 years have passed since last update.

Perlでたらいまわし関数

Last updated at Posted at 2012-03-16
tarai.pl
#!/usr/bin/env perl
use strict;
use warnings;

my $count = 0;

sub tarai {
    my ( $x, $y, $z ) = @_;

    $count++;
    warn "$count: tarai($x, $y, $z)\n";

    if ( $x <= $y ) {
        return $y;
    }
    else {
        return tarai(
            tarai( $x - 1, $y, $z ),
            tarai( $y - 1, $z, $x ),
            tarai( $z - 1, $x, $y )
        );
    }
}

my @args = ( @ARGV >= 3 ) ? @ARGV : ( 10, 5, 0 );

print tarai(@args), "\n";
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1