Fixed the bug of not outputing the correct least common multiple of given numbers
parent
f0f7e84118
commit
19da7511b4
|
@ -29,14 +29,10 @@ handle remainder => sub {
|
|||
|
||||
my $formatted_numbers = join(', ', @numbers);
|
||||
$formatted_numbers =~ s/, ([^,]*)$/ and $1/;
|
||||
|
||||
my $gcd = $numbers[0];
|
||||
|
||||
my $lcm = 1;
|
||||
foreach (@numbers) {
|
||||
$gcd = gcf($gcd, $_);
|
||||
}
|
||||
my $lcm = shift @numbers;
|
||||
foreach (@numbers) {
|
||||
$lcm *= $_ / $gcd;
|
||||
$lcm = $lcm * $_ / gcf($lcm, $_);
|
||||
}
|
||||
|
||||
return "Least common multiple of $formatted_numbers is $lcm.",
|
||||
|
|
|
@ -63,7 +63,7 @@ ddg_goodie_test(
|
|||
structured_answer => {
|
||||
input => ['12, 18 and 24'],
|
||||
operation => 'Least common multiple',
|
||||
result => 144
|
||||
result => 72
|
||||
}
|
||||
),
|
||||
'lcm 6, 9, ,,,, 12 15' => test_zci(
|
||||
|
@ -71,7 +71,7 @@ ddg_goodie_test(
|
|||
structured_answer => {
|
||||
input => ['6, 9, 12 and 15'],
|
||||
operation => 'Least common multiple',
|
||||
result => 360
|
||||
result => 180
|
||||
}
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue