How to resolve the algorithm Abbreviations, automatic step by step in the Racket programming language
How to resolve the algorithm Abbreviations, automatic step by step in the Racket 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.
It would make a list of words easier to maintain (as words are added, changed, and/or deleted) if the minimum abbreviation length of that list could be automatically (programmatically) determined.
For this task, use the list (below) of the days-of-the-week names that are expressed in about a hundred languages (note that there is a blank line in the list). Caveat: The list (above) most surely contains errors (or, at the least, differences) of what the actual (or true) names for the days-of-the-week.
To make this Rosetta Code task page as small as possible, if processing the complete list, read the days-of-the-week from a file (that is created from the above list).
Notes concerning the above list of words
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Abbreviations, automatic step by step in the Racket programming language
Source code in the racket programming language
#lang racket
(require racket/set)
(define (abbr-length ss)
(for*/first ((l (in-range 1 (string-length (argmax string-length ss))))
#:when (equal? (sequence-length
(for/set ((s ss))
(substring s 0 (min l (string-length s)))))
(length ss)))
l))
(module+ main
(define report-line
(match-lambda
["" ""]
[(and s (app string-split ss)) (format "~a ~a" (abbr-length ss) s)]))
(for-each (compose displayln report-line) (take (file->lines "data.txt") 5)))
You may also check:How to resolve the algorithm Test a function step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Uniface programming language
You may also check:How to resolve the algorithm Palindromic gapful numbers step by step in the zkl programming language
You may also check:How to resolve the algorithm Vigenère cipher/Cryptanalysis step by step in the 11l programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the jq programming language