Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 24 lines (21 sloc) 0.528 kB
#!/usr/bin/env perl
use strict;
use warnings;
use rlib '../lib';
use Enbugger 'trepan';
# GCD. We assume positive numbers
sub gcd($$);
sub gcd($$)
{
Enbugger->stop;
my ($a, $b) = @_;
# Make: a <= b
($a, $b) = ($b, $a) if ($a > $b);
return undef if $a <= 0;
return $a if ($a == 1) or ($b-$a == 0);
return gcd($b-$a, $a);
}
die sprintf "Need two integer arguments, got %d", scalar(@ARGV) unless
@ARGV == 2;
my ($a, $b) = @ARGV[0,1];
printf "The GCD of %d and %d is %d\n", $a, $b, gcd($a, $b);
Jump to Line
Something went wrong with that request. Please try again.