Skip to content

Instantly share code, notes, and snippets.

@EricCrosson
Created March 30, 2013 03:58
Show Gist options
  • Save EricCrosson/8b5dc6a15679f159f7fc to your computer and use it in GitHub Desktop.
Save EricCrosson/8b5dc6a15679f159f7fc to your computer and use it in GitHub Desktop.
A recursive perl script to find the greatest common denominator of two integers.
#!/usr/bin/perl -w
use strict;
sub gcd {
my ($m, $n) = @_;
if ($n == 0) {
return $m;
}
return gcd($n, $m % $n);
}
sub main {
gcd($ARGV[0], $ARGV[1]);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment