How to resolve the algorithm Abbreviations, easy step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Abbreviations, easy step by step in the zkl programming language

Table of Contents

Problem Statement

This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple.

For this task, the following   command table   will be used:

Notes concerning the above   command table:

For a user string of: the computer program should return the string:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Abbreviations, easy step by step in the zkl programming language

Source code in the zkl programming language

commands:=Data(0,String,	// "Add\0ALTer\0..."
#<<<
"Add ALTer  BAckup Bottom  CAppend Change SCHANGE  CInsert CLAst COMPress COpy
 COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
 NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput
 Join SPlit SPLTJOIN  LOAD  Locate CLocate  LOWercase UPPercase  LPrefix MACRO
 MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD  Query  QUIT
 READ  RECover REFRESH RENum REPeat  Replace CReplace  RESet  RESTore  RGTLEFT
 RIght LEft  SAVE  SET SHift SI  SORT  SOS  STAck STATus  TOP TRAnsfer Type Up "
.split());
#<<<

testText:=" riG   rePEAT copies  put mo   rest    types "
	  "fup.    6       poweRin";

testText.split().apply('wrap(word){ 
   sz,w := word.len(),word + "*";
   foreach c in (commands){	// rather inelegant but gotta ignore case
      // check for length requirement and, if there, verify
      if(c.matches(w) and sz>=(c-"abcdefghijklmnopqrstuvwxyz").len())
	 return(c.toUpper());
   }
   "*error*"
.concat(" ").println();

  

You may also check:How to resolve the algorithm Special characters step by step in the Quackery programming language
You may also check:How to resolve the algorithm Guess the number step by step in the LabVIEW programming language
You may also check:How to resolve the algorithm Palindromic gapful numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the Raku programming language
You may also check:How to resolve the algorithm Find duplicate files step by step in the Python programming language