How to resolve the algorithm Find common directory path step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Find common directory path step by step in the 11l programming language

Table of Contents

Problem Statement

Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories. Test your routine using the forward slash '/' character as the directory separator and the following three strings as input paths: Note: The resultant path should be the valid directory '/home/user1/tmp' and not the longest common string '/home/user1/tmp/cove'. If your language has a routine that performs this function (even if it does not have a changeable separator character), then mention it as part of the task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Find common directory path step by step in the 11l programming language

Source code in the 11l programming language

F find_common_directory_path(paths, sep = ‘/’)
   V pos = 0
   L
      L(path) paths
         I pos < path.len & path[pos] == paths[0][pos]
            L.continue

         L pos > 0
            pos--
            I paths[0][pos] == sep
               L.break
         R paths[0][0.
      pos++

print(find_common_directory_path([
   ‘/home/user1/tmp/coverage/test’,
   ‘/home/user1/tmp/covert/operator’,
   ‘/home/user1/tmp/coven/members’]))

  

You may also check:How to resolve the algorithm Loops/With multiple ranges step by step in the C programming language
You may also check:How to resolve the algorithm Abbreviations, simple step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Get system command output step by step in the LIL programming language
You may also check:How to resolve the algorithm Van der Corput sequence step by step in the Delphi programming language
You may also check:How to resolve the algorithm Population count step by step in the CLU programming language