How to resolve the algorithm Abbreviations, simple step by step in the AutoHotkey programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Abbreviations, simple step by step in the AutoHotkey programming language
Table of Contents
Problem Statement
The use of abbreviations (also sometimes called synonyms, nicknames, AKAs, or aliases) can be an easy way to add flexibility when specifying or using commands, sub─commands, options, etc.
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, simple step by step in the AutoHotkey programming language
Source code in the autohotkey programming language
table := "
(
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2 findUP 3 fUP 2
forward 2 get help 1 hexType 4 input 1 powerInput 3 join 1 split 2 spltJOIN load
locate 1 Clocate 2 lowerCase 3 upperCase 3 Lprefix 2 macro merge 2 modify 3 move 2
msg next 1 overlay 1 parse preserve 4 purge 3 put putD query 1 quit read recover 3
refresh renum 3 repeat 3 replace 1 Creplace 2 reset 3 restore 4 rgtLEFT right 2 left
2 save set shift 2 si sort sos stack 3 status 4 top transfer 3 type 1 up 1
)"
MsgBox % result := Abbreviations("riG rePEAT copies put mo rest types fup. 6 poweRin", table)
return
Abbreviations(str, table){
Words := [], Expanded := []
while pos := RegExMatch(table, "i)([a-z]+)(?:\s+(\d+))?", m, A_Index=1?1:pos+StrLen(m))
Words[m1] := m2?m2:StrLen(m1)
for i, abb in StrSplit(RegExReplace(str, " +", " "), " ")
{
for word, count in Words
if (word ~= "i)^" abb) && (StrLen(abb) >= count)
{
StringUpper, word, word
result .= word " "
Expanded[abb] := true
break
}
if !Expanded[abb]
result .= "*error* "
}
return Trim(result, " ")
}
You may also check:How to resolve the algorithm Ackermann function step by step in the TXR programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the LOLCODE programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Machine code step by step in the Z80 Assembly programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the FALSE programming language