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

Published on 12 May 2024 09:40 PM

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

Source code in the run programming language

' ------------------------------------------
' Find common directory to all directories
' and directories common with other Paths
' ------------------------------------------
print word$(word$(httpget$("http://tycho.usno.navy.mil/cgi-bin/timer.pl"),1,"UTC"),2,"
") ' Universal time
dim path$(20) path$(1) = "/home/user1/tmp/coverage/test" path$(2) = "/home/user1/tmp/covert/operator" path$(3) = "/home/user1/tmp/coven/members" path$(4) = "/home/user1/tmp1/coverage/test" path$(5) = "/home/user1/tmp1/covert/operator" path$(6) = "/home/user1/tmp1/coven/members" path$(7) = "/home/user1/tmp2/coverage/test" path$(8) = "/home/user1/tmp2/covert/operator" path$(9) = "/home/user1/tmp2/coven/members" path$(10) = "/home/user1/tmp3/coverage/test" path$(11) = "/home/user1/tmp3/covert/operator" path$(12) = "/home/user1/tmp3/coven/members" sqliteconnect #mem, ":memory:" #mem execute("CREATE TABLE dirTree (seq,pos,dir)") for i = 1 to 12 j = 1 [loop] j = instr(path$(i),"/",j + 1) if j > 0 then dir$ = mid$(path$(i),1,j) mem$ = "INSERT INTO dirTree VALUES (";i;",";j;",'";dir$;"')" #mem execute(mem$) goto [loop] end if next i mem$ = "SELECT dir FROM dirTree GROUP BY dir HAVING count(*) = pos ORDER BY pos desc LIMIT 1" #mem execute(mem$) rows = #mem ROWCOUNT() 'Get the number of rows if rows > 0 then #row = #mem #nextrow() print "====== Largest Directory Common to all Paths =========" print #row dir$() else print "No common Directory" end if html "
"
print "========= Common paths ================" mem$ = "SELECT t.seq as seq,t.pos as pos,t.dir as dir,t1.seq as t1Seq ,t1.dir as t1Dir FROM dirTree as t JOIN dirTree as t1 ON t1.dir = t.dir AND t1.seq > t.seq GROUP BY t.dir,t1.seq" html ""#mem execute(mem$)WHILE #mem hasanswer() #row = #mem #nextrow() seq = #row seq() t1Seq = #row t1Seq() pos = #row pos() dir$ = #row dir$() t1Dir$ = #row t1Dir$()html ""html ""html ""html ""html ""html ""html ""WENDhtml "
Seq Path Common Dir Seq With Path
";seq;" ";path$(seq);" ";dir$;" ";t1Seq;" ";path$(t1Seq);"
"
wait end

You may also check:How to resolve the algorithm String concatenation step by step in the Frink programming language
You may also check:How to resolve the algorithm Harmonic series step by step in the Go programming language
You may also check:How to resolve the algorithm Quine step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Department numbers step by step in the Aime programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the PHP programming language