The solutions in the Raku programming language of the challenges offered on Week 2 of the Perl Weekly Challenges.
Remove leading zeros from positive numbers.
So, we need to take a string such as
000042 and print it as
42. Even here, there are two obvious solutions:
my $n = '00000042'; say +$n; say $n.Int;
A prefix form of
+ converts the string to an integer. The same can be done by an explicit call of the
The program prints the expected number:
$ raku ch-1.raku
Convert a number to the one represented as a base-35 number and back.
In Raku, there is a pair of routines,
parse-base. They are ideal tools for solving the task.
To convert the number, use
my $n = 2020; my $n35 = $n.base(35); say $n35;
To convert it back to decimal system, use
my $n10 = $n35.parse-base(35); say $n10;
After this operation, the program prints the initial number
Look for the source files in the folder 002 of the GitHub repository.