How to resolve the algorithm Range expansion step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Range expansion step by step in the J programming language

Table of Contents

Problem Statement

A format for expressing an ordered list of integers is to use a comma separated list of either Example The list of integers: Is accurately expressed by the range expression: (And vice-versa).

Expand the range description: Note that the second element above, is the range from minus 3 to minus 1.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Range expansion step by step in the J programming language

Source code in the j programming language

require'strings'
thru=: <. + i.@(+*)@-~
num=: _&".
normaliz=: rplc&(',-';',_';'--';'-_')@,~&','
subranges=:<@(thru/)@(num;._2)@,&'-';._1
rngexp=: ;@subranges@normaliz


   rngexp '-6,-3--1,3-5,7-11,14,15,17-20'
_6 _3 _2 _1 3 4 5 7 8 9 10 11 14 15 17 18 19 20


  

You may also check:How to resolve the algorithm Dot product step by step in the GAP programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the Wren programming language
You may also check:How to resolve the algorithm Modular arithmetic step by step in the Factor programming language
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the Fortran programming language
You may also check:How to resolve the algorithm Loops/While step by step in the Dc programming language