How to resolve the algorithm Sort numbers lexicographically step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sort numbers lexicographically step by step in the Raku programming language

Table of Contents

Problem Statement

Given an integer   n,   return   1──►n   (inclusive)   in lexicographical order.

Show all output here on this page.

Given   13, return:   [1,10,11,12,13,2,3,4,5,6,7,8,9].

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sort numbers lexicographically step by step in the Raku programming language

Source code in the raku programming language

sub lex (Real $n, $step = 1) {
    ($n < 1 ?? ($n, * + $step …^ * > 1)
            !! ($n, * - $step …^ * < 1)).sort: ~*
}

# TESTING
for 13, 21, -22, (6, .333), (-4, .25), (-5*π, e) {
    my ($bound, $step) = |$_, 1;
    say "Boundary:$bound, Step:$step >> ", lex($bound, $step).join: ', ';
}


  

You may also check:How to resolve the algorithm Truth table step by step in the C programming language
You may also check:How to resolve the algorithm Count occurrences of a substring step by step in the Java programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the friendly interactive shell programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the Ursala programming language
You may also check:How to resolve the algorithm Metaprogramming step by step in the FreeBASIC programming language