How to resolve the algorithm Abbreviations, automatic step by step in the F# programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Abbreviations, automatic step by step in the F# 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 F# programming language

Source code in the fsharp programming language

let fN g=let rec fN n=if g|>List.map(fun(g:string)->g.[0..n])|>Set.ofList|>Set.count=(List.length g) then (n+1) else fN(n+1)
         fN 0


fN ["Sunday"; "Monday"; "Tuesday"; "Wednesday"; "Thursday"; "Friday"; "Saturday"]                  // -> 2
fN ["Sondag"; "Maandag"; "Dinsdag"; "Woensdag"; "Donderdag"; "Vrydag"; "Saterdag"]                 // -> 2
fN ["E_djelë"; "E_hënë"; "E_martë"; "E_mërkurë"; "E_enjte"; "E_premte"; "E_shtunë"]                // -> 4
fN ["Ehud"; "Segno"; "Maksegno"; "Erob"; "Hamus"; "Arbe"; "Kedame"]                                // -> 2
fN ["Al_Ahad"; "Al_Ithinin"; "Al_Tholatha'a"; "Al_Arbia'a"; "Al_Kamis"; "Al_Gomia'a"; "Al_Sabit";] // -> 5


  

You may also check:How to resolve the algorithm Pig the dice game step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Convert decimal number to rational step by step in the zkl programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Function definition step by step in the PowerShell programming language