How to resolve the algorithm Abbreviations, easy step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Abbreviations, easy step by step in the Racket 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 Racket programming language
Source code in the racket programming language
#lang racket
(define command-string
"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")
(define input-string
"riG rePEAT copies put mo rest types fup. 6 poweRin")
(define (make-command command)
(cons (string-upcase command)
(list->string (takef (string->list command) char-upper-case?))))
(define commands (map make-command (string-split command-string)))
(string-join
(for/list ([s (in-list (string-split input-string))])
(define up (string-upcase s))
(or (for/or ([command (in-list commands)])
(match-define (cons full-command abbrev) command)
(and (string-prefix? up abbrev)
(string-prefix? full-command up)
full-command))
"*error*"))
" ")
You may also check:How to resolve the algorithm Bitmap/PPM conversion through a pipe step by step in the Python programming language
You may also check:How to resolve the algorithm Square but not cube step by step in the Ksh programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Fexl programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the Nim programming language
You may also check:How to resolve the algorithm Concurrent computing step by step in the Egel programming language