Finding stepping numbers in Raku

Here is a possible solution of the Task 1 of Week 52 of the Perl Weekly Challenge in the Raku programming language.

Find all stepping numbers between 100 and 999. A number is called a stepping number if the adjacent digits have a difference of 1.

Here is a possible solution of the Task 1 of Week 52 of the Perl Weekly Challenge in the Raku programming language.

Find all stepping numbers between 100 and 999. A number is called a stepping number if the adjacent digits have a difference of 1.

Let us use brute force the test if the digits are distant by 1. Generate a sequence 100...999 or a range 100..999 and filter it using the obvious conditions:

my $a = 100;
my $b = 999;

.say for grep {
    .comb[1] - .comb[0] == 1 &&
    .comb[2] - .comb[1] == 1
}, $a .. $b;

This program prints the following result:

$ raku ch-1.raku 
123
234
345
456
567
678
789

GitHub repository
Navigation to the Raku challenges post series

Leave a Reply

Your email address will not be published. Required fields are marked *