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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Find common directory path step by step in the Ursala 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 Ursala programming language

Source code in the ursala programming language

#import std

comdir"s" "p" = mat"s" reduce(gcp,0) (map sep "s") "p"

comdir"s" "p" = mat"s" gcp:-0 sep"s"* "p"

comdir"s" = mat"s"+ gcp:-0+ sep"s"*

comdir = +^/mat gcp:-0++ *+ sep

#cast %s

test = 

comdir`/ <
   '/home/user1/tmp/coverage/test',
   '/home/user1/tmp/covert/operator',
   '/home/user1/tmp/coven/members'>

  

You may also check:How to resolve the algorithm XML/XPath step by step in the PHP programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the GW-BASIC programming language
You may also check:How to resolve the algorithm Sierpinski carpet step by step in the Fennel programming language
You may also check:How to resolve the algorithm Use another language to call a function step by step in the Wren programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Run BASIC programming language