September 2017
Beginner
402 pages
9h 52m
English
The gcd and lcm operators calculate the great common divisor and the least common multiple for the given two numbers. These operators are usually not included in the list of operators built into many other languages. In Perl 6, however, you don't need to include any libraries to use them. Consider the following examples of using the gcd and lcm operators:
my $a = 20;my $b = 30;say $a gcd $b; # Prints 10say $a lcm $b; # Prints 60
Notice that the syntax requires that both gcd and lcm names are used as operators, not as functions. The following code is incorrect:
say gcd($a, $b);say lcm($a, $b);
It will generate compiling errors, as you can see here:
===SORRY!=== Error while compiling ...
Read now
Unlock full access