June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,12 +1,12 @@
sub gcd {
my ($a, $b) = @_;
while ($a) { ($a, $b) = ($b % $a, $a) }
$b
my ($x, $y) = @_;
while ($x) { ($x, $y) = ($y % $x, $x) }
$y
}
sub lcm {
my ($a, $b) = @_;
($a && $b) and $a / gcd($a, $b) * $b or 0
my ($x, $y) = @_;
($x && $y) and $x / gcd($x, $y) * $y or 0
}
print lcm(1001, 221);

View file

@ -1,13 +1,13 @@
sub lcm {
use integer;
my ($x, $y) = @_;
my ($a, $b) = @_;
while ($a != $b) {
($a, $b, $x, $y) = ($b, $a, $y, $x) if $a > $b;
$a = $b / $x * $x;
$a += $x if $a < $b;
my ($f, $s) = @_;
while ($f != $s) {
($f, $s, $x, $y) = ($s, $f, $y, $x) if $f > $s;
$f = $s / $x * $x;
$f += $x if $f < $s;
}
$a
$f
}
print lcm(1001, 221);