langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,27 @@
|
|||
let rec aux acc paths =
|
||||
if List.mem [] paths
|
||||
then (List.rev acc) else
|
||||
let heads = List.map List.hd paths in
|
||||
let item = List.hd heads in
|
||||
let all_the_same =
|
||||
List.for_all ((=) item) (List.tl heads)
|
||||
in
|
||||
if all_the_same
|
||||
then aux (item::acc) (List.map List.tl paths)
|
||||
else (List.rev acc)
|
||||
|
||||
let common_prefix sep = function
|
||||
| [] -> invalid_arg "common_prefix"
|
||||
| dirs ->
|
||||
let paths = List.map (Str.split (Str.regexp_string sep)) dirs in
|
||||
let res = aux [] paths in
|
||||
(sep ^ (String.concat sep res))
|
||||
|
||||
let () =
|
||||
let dirs = [
|
||||
"/home/user1/tmp/coverage/test";
|
||||
"/home/user1/tmp/covert/operator";
|
||||
"/home/user1/tmp/coven/members";
|
||||
] in
|
||||
print_endline (common_prefix "/" dirs);
|
||||
;;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
FUNCTION findCommonDir RETURNS CHAR(
|
||||
i_cdirs AS CHAR,
|
||||
i_cseparator AS CHAR
|
||||
):
|
||||
|
||||
DEF VAR idir AS INT.
|
||||
DEF VAR idepth AS INT.
|
||||
DEF VAR cdir AS CHAR EXTENT.
|
||||
DEF VAR lsame AS LOGICAL INITIAL TRUE.
|
||||
DEF VAR cresult AS CHAR.
|
||||
|
||||
EXTENT( cdir ) = NUM-ENTRIES( i_cdirs, '~n' ).
|
||||
|
||||
DO idir = 1 TO NUM-ENTRIES( i_cdirs, '~n' ):
|
||||
cdir[ idir ] = ENTRY( idir, i_cdirs, '~n' ).
|
||||
END.
|
||||
|
||||
DO idepth = 2 TO NUM-ENTRIES( cdir [ 1 ], i_cseparator ) WHILE lsame:
|
||||
DO idir = 1 TO EXTENT( cdir ) - 1 WHILE lsame:
|
||||
lsame = (
|
||||
ENTRY( idepth, cdir [ idir ], i_cseparator ) =
|
||||
ENTRY( idepth, cdir [ idir + 1 ], i_cseparator )
|
||||
).
|
||||
END.
|
||||
IF lsame THEN
|
||||
cresult = cresult + i_cseparator + ENTRY( idepth, cdir [ 1 ], i_cseparator ).
|
||||
END.
|
||||
|
||||
RETURN cresult.
|
||||
|
||||
END FUNCTION.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
MESSAGE
|
||||
findCommonDir(
|
||||
'/home/user1/tmp/coverage/test' + '~n' +
|
||||
'/home/user1/tmp/covert/operator' + '~n' +
|
||||
'/home/user1/tmp/coven/members',
|
||||
'/'
|
||||
)
|
||||
VIEW-AS ALERT-BOX
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
declare
|
||||
fun {CommonPrefix Sep Paths}
|
||||
fun {GetParts P} {String.tokens P Sep} end
|
||||
Parts = {ZipN {Map Paths GetParts}}
|
||||
EqualParts = {List.takeWhile Parts fun {$ X|Xr} {All Xr {Equals X}} end}
|
||||
in
|
||||
{Join Sep {Map EqualParts Head}}
|
||||
end
|
||||
|
||||
fun {ZipN Xs}
|
||||
if {Some Xs {Equals nil}} then nil
|
||||
else
|
||||
{Map Xs Head} | {ZipN {Map Xs Tail}}
|
||||
end
|
||||
end
|
||||
|
||||
fun {Join Sep Xs}
|
||||
{FoldR Xs fun {$ X Z} {Append X Sep|Z} end nil}
|
||||
end
|
||||
|
||||
fun {Equals C}
|
||||
fun {$ X} X == C end
|
||||
end
|
||||
|
||||
fun {Head X|_} X end
|
||||
|
||||
fun {Tail _|Xr} Xr end
|
||||
in
|
||||
{System.showInfo {CommonPrefix &/
|
||||
["/home/user1/tmp/coverage/test"
|
||||
"/home/user1/tmp/covert/operator"
|
||||
"/home/user1/tmp/coven/members"]}}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
cdp(v)={
|
||||
my(s="");
|
||||
v=apply(t->Vec(t),v);
|
||||
for(i=1,vecmin(apply(length,v)),
|
||||
for(j=2,#v,
|
||||
if(v[j][i]!=v[1][i],return(s)));
|
||||
if(i>1&v[1][i]=="/",s=concat(vecextract(v[1],1<<(i-1)-1))
|
||||
)
|
||||
);
|
||||
if(vecmax(apply(length,v))==vecmin(apply(length,v)),concat(v[1]),s)
|
||||
};
|
||||
cdp(["/home/user1/tmp/coverage/test","/home/user1/tmp/covert/operator","/home/user1/tmp/coven/members"])
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
my $sep = '/';
|
||||
my @dirs = </home/user1/tmp/coverage/test
|
||||
/home/user1/tmp/covert/operator
|
||||
/home/user1/tmp/coven/members>;
|
||||
|
||||
my @comps = @dirs.map: { [ .comb(/ $sep [ <!before $sep> . ]* /) ] };
|
||||
|
||||
my $prefix = '';
|
||||
|
||||
while all(@comps[*]»[0]) eq @comps[0][0] {
|
||||
$prefix ~= @comps[0][0] // last;
|
||||
@comps».shift;
|
||||
}
|
||||
|
||||
say "The longest common path is $prefix";
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
my $sep := '/';
|
||||
my @dirs := </home/user1/tmp/coverage/test
|
||||
/home/user1/tmp/covert/operator
|
||||
/home/user1/tmp/coven/members>;
|
||||
|
||||
my @comps := @dirs.map: { [ .comb(/ $sep [ <!before $sep> . ]* /) ] };
|
||||
|
||||
say "The longest common path is ",
|
||||
gather for 0..* -> $column {
|
||||
last unless all(@comps[*]»[$column]) eq @comps[0][$column];
|
||||
take @comps[0][$column] // last;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
my $sep = '/';
|
||||
my @dirs = </home/user1/tmp/coverage/test
|
||||
/home/user1/tmp/covert/operator
|
||||
/home/user1/tmp/coven/members>;
|
||||
|
||||
sub is_common_prefix { so $^prefix eq all(@dirs).substr(0, $prefix.chars) }
|
||||
|
||||
say ([\~] @dirs.comb(/ $sep [ <!before $sep> . ]* /)).reverse.first: &is_common_prefix
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
array paths = ({ "/home/user1/tmp/coverage/test",
|
||||
"/home/user1/tmp/covert/operator",
|
||||
"/home/user1/tmp/coven/members" });
|
||||
|
||||
// append a / to each entry, so that a path like "/home/user1/tmp" will be recognized as a prefix
|
||||
// without it the prefix would end up being "/home/user1/"
|
||||
paths = paths[*]+"/";
|
||||
|
||||
string cp = String.common_prefix(paths);
|
||||
cp = cp[..sizeof(cp)-search(reverse(cp), "/")-2];
|
||||
Result: "/home/user1/tmp"
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
# Find Common Directory Path
|
||||
# Input is an array of strings holding the paths
|
||||
function Get-CommonDirectoryPath($paths){
|
||||
|
||||
# Convert each path into array of tokens (i.e. convert array into jagged array)
|
||||
for($i=0; $i -lt $paths.Count; $i++) {
|
||||
$paths[$i] = ($paths[$i].TrimStart('/').Split('/'))
|
||||
}
|
||||
|
||||
# Loop through tokens
|
||||
$c = -1
|
||||
$found = $false
|
||||
do { # Do Until loop used to handle paths with different number of directories
|
||||
$t = $paths[0][++$c]
|
||||
for($r = 1; $r -lt $paths.Count; $r++) {
|
||||
if ($t -ne $paths[$r][$c]) { $found=$true; break }
|
||||
}
|
||||
} until ($found)
|
||||
|
||||
# Return the answer
|
||||
for($i=0; $i -lt $c; $i++) {$s += "/"+$paths[0][$i]}
|
||||
return $s
|
||||
}
|
||||
|
||||
# Main Entry Point
|
||||
"The common directory path is " + (Get-CommonDirectoryPath ("/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members"))
|
||||
|
|
@ -0,0 +1 @@
|
|||
The common directory path is /home/user1/tmp
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
Procedure.s CommonPath(Array InPaths.s(1),separator.s="/")
|
||||
Protected SOut$=""
|
||||
Protected i, j, toggle
|
||||
|
||||
If ArraySize(InPaths())=0
|
||||
ProcedureReturn InPaths(0) ; Special case, only one path
|
||||
EndIf
|
||||
|
||||
Repeat
|
||||
i+1
|
||||
toggle=#False
|
||||
For j=1 To ArraySize(InPaths())
|
||||
If (StringField(InPaths(j-1),i,separator)=StringField(InPaths(j),i,separator))
|
||||
If Not toggle
|
||||
SOut$+StringField(InPaths(j-1),i,separator)+separator
|
||||
toggle=#True
|
||||
EndIf
|
||||
Else
|
||||
ProcedureReturn SOut$
|
||||
EndIf
|
||||
Next
|
||||
ForEver
|
||||
EndProcedure
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Dim t.s(2)
|
||||
t(0)="/home/user1/tmp/coverage/test"
|
||||
t(1)="/home/user1/tmp/covert/operator"
|
||||
t(2)="/home/user1/tmp/coven/members"
|
||||
|
||||
Debug CommonPath(t(),"/"))
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
' ------------------------------------------
|
||||
' 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,"<BR>") ' 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 "<HR>"
|
||||
|
||||
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 "<table border=1><TR align=center>
|
||||
<TD>Seq</TD>
|
||||
<TD>Path</TD>
|
||||
<TD>Common Dir</TD>
|
||||
<TD>Seq</TD>
|
||||
<TD>With Path</TD></TR>"
|
||||
|
||||
#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 "<TR>"
|
||||
html "<TD>";seq;"</TD>"
|
||||
html "<TD>";path$(seq);"</TD>"
|
||||
html "<TD>";dir$;"</TD>"
|
||||
html "<TD>";t1Seq;"</TD>"
|
||||
html "<TD>";path$(t1Seq);"</TD>"
|
||||
html "</TR>"
|
||||
WEND
|
||||
html "</TABLE>"
|
||||
wait
|
||||
end
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const func integer: commonLen (in array string: names, in char: sep) is func
|
||||
result
|
||||
var integer: result is -1;
|
||||
local
|
||||
var integer: index is 0;
|
||||
var integer: pos is 1;
|
||||
begin
|
||||
if length(names) <> 0 then
|
||||
repeat
|
||||
for index range 1 to length(names) do
|
||||
if pos > length(names[index]) or names[index][pos] <> names[1][pos] then
|
||||
decr(pos);
|
||||
while pos >= 1 and names[1][pos] <> sep do
|
||||
decr(pos);
|
||||
end while;
|
||||
if pos > 1 then
|
||||
decr(pos);
|
||||
end if;
|
||||
result := pos;
|
||||
end if;
|
||||
end for;
|
||||
incr(pos);
|
||||
until result <> -1;
|
||||
end if;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var integer: length is 0;
|
||||
const array string: names is [] ("/home/user1/tmp/coverage/test",
|
||||
"/home/user1/tmp/covert/operator",
|
||||
"/home/user1/tmp/coven/members")
|
||||
begin
|
||||
length := commonLen(names, '/');
|
||||
if length = 0 then
|
||||
writeln("No common path");
|
||||
else
|
||||
writeln("Common path: " <& names[1][.. length]);
|
||||
end if;
|
||||
end func;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
$$ MODE TUSCRIPT
|
||||
common=""
|
||||
dir1="/home/user1/tmp/coverage/test"
|
||||
dir2="/home/user1/tmp/covert/operator"
|
||||
dir3="/home/user1/tmp/coven/members"
|
||||
dir1=SPLIT (dir1,":/:"),dir2=SPLIT (dir2,":/:"), dir3=SPLIT (dir3,":/:")
|
||||
LOOP d1=dir1,d2=dir2,d3=dir3
|
||||
IF (d1==d2,d3) THEN
|
||||
common=APPEND(common,d1,"/")
|
||||
ELSE
|
||||
PRINT common
|
||||
EXIT
|
||||
ENDIF
|
||||
ENDLOOP
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
|
||||
pathlist='/home/user1/tmp/coverage/test
|
||||
/home/user1/tmp/covert/operator
|
||||
/home/user1/tmp/coven/members'
|
||||
|
||||
i=2
|
||||
|
||||
while [ $i -lt 100 ]
|
||||
do
|
||||
path=`echo "$pathlist" | cut -f1-$i -d/ | uniq -d`
|
||||
if [ -z "$path" ]
|
||||
then
|
||||
echo $prev_path
|
||||
break
|
||||
else
|
||||
prev_path=$path
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#import std
|
||||
|
||||
comdir"s" "p" = mat"s" reduce(gcp,0) (map sep "s") "p"
|
||||
|
|
@ -0,0 +1 @@
|
|||
comdir"s" "p" = mat"s" gcp:-0 sep"s"* "p"
|
||||
|
|
@ -0,0 +1 @@
|
|||
comdir"s" = mat"s"+ gcp:-0+ sep"s"*
|
||||
|
|
@ -0,0 +1 @@
|
|||
comdir = +^/mat gcp:-0++ *+ sep
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#cast %s
|
||||
|
||||
test =
|
||||
|
||||
comdir`/ <
|
||||
'/home/user1/tmp/coverage/test',
|
||||
'/home/user1/tmp/covert/operator',
|
||||
'/home/user1/tmp/coven/members'>
|
||||
Loading…
Add table
Add a link
Reference in a new issue