How to resolve the algorithm Range extraction step by step in the MUMPS programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Range extraction step by step in the MUMPS 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).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Range extraction step by step in the MUMPS programming language

Source code in the mumps programming language

RANGCONT(X) ;Integer range contraction
 NEW Y,I,CONT,NOTFIRST,CURR,PREV,NEXT,SEQ SET Y="",SEQ=0,PREV="",CONT=0
 FOR I=1:1:$LENGTH(X,",") DO
 .SET NOTFIRST=$LENGTH(Y),CURR=$PIECE(X,",",I),NEXT=$PIECE(X,",",I+1)
 .FOR  Q:$EXTRACT(CURR)'=" "  S CURR=$EXTRACT(CURR,2,$LENGTH(CURR))  ;clean up leading spaces
 .S SEQ=((CURR-1)=PREV)&((CURR+1)=NEXT)
 .IF 'NOTFIRST SET Y=CURR
 .IF NOTFIRST DO
 ..;Order matters due to flags
 ..IF CONT&SEQ ;Do nothing
 ..IF 'CONT&'SEQ SET Y=Y_","_CURR
 ..IF CONT&'SEQ SET Y=Y_CURR,CONT=0
 ..IF 'CONT&SEQ SET Y=Y_"-",CONT=1
 .SET PREV=CURR
 IF CONT SET Y=Y_PREV
 K I,CONT,NOTFIRST,CURR,PREV,NEXT,SEQ
 QUIT Y

  

You may also check:How to resolve the algorithm Anagrams step by step in the Go programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Pony programming language
You may also check:How to resolve the algorithm Apply a callback to an array step by step in the J programming language
You may also check:How to resolve the algorithm Anonymous recursion step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Xiaolin Wu's line algorithm step by step in the Haskell programming language