Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/lasso9
|
||||
|
||||
local(
|
||||
path1 = '/home/user1/tmp/coverage/test' -> split('/'),
|
||||
path2 = '/home/user1/tmp/covert/operator' -> split('/'),
|
||||
path3 = '/home/user1/tmp/coven/members' -> split('/')
|
||||
)
|
||||
|
||||
define commonpath(...) => {
|
||||
local(shared = #rest -> get(1))
|
||||
loop(#rest -> size - 1) => {
|
||||
#shared = #shared -> intersection(#rest -> get(loop_count + 1))
|
||||
}
|
||||
return #shared -> join('/')
|
||||
}
|
||||
|
||||
stdoutnl(commonpath(#path1, #path2, #path3))
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
on getCommonPath (pathes, sep)
|
||||
_player.itemDelimiter = sep
|
||||
|
||||
-- find length of shortest path (in terms of items)
|
||||
commonCnt = the maxInteger
|
||||
repeat with p in pathes
|
||||
if p.item.count<commonCnt then commonCnt=p.item.count
|
||||
end repeat
|
||||
|
||||
pathCnt = pathes.count
|
||||
repeat with i = 1 to commonCnt
|
||||
repeat with j = 2 to pathCnt
|
||||
if pathes[j].item[i]<>pathes[j-1].item[i] then
|
||||
return pathes[1].item[1..i-1]
|
||||
end if
|
||||
end repeat
|
||||
end repeat
|
||||
return pathes[1].item[1..commonCnt]
|
||||
end
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
pathes = []
|
||||
pathes.add("/home/user1/tmp/coverage/test")
|
||||
pathes.add("/home/user1/tmp/covert/operator")
|
||||
pathes.add("/home/user1/tmp/coven/members")
|
||||
|
||||
put getCommonPath(pathes, "/")
|
||||
-- "/home/user1/tmp"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import strutils
|
||||
|
||||
proc commonprefix(paths: openarray[string], sep = "/"): string =
|
||||
if paths.len == 0: return ""
|
||||
block outer:
|
||||
for i in 0..paths[0].len:
|
||||
result = paths[0][0..i]
|
||||
for path in paths:
|
||||
if not path.startsWith(result):
|
||||
break outer
|
||||
result = result[0 .. <result.rfind(sep)]
|
||||
|
||||
echo commonprefix(@["/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members"])
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
var dirs = %w(
|
||||
/home/user1/tmp/coverage/test
|
||||
/home/user1/tmp/covert/operator
|
||||
/home/user1/tmp/coven/members
|
||||
);
|
||||
|
||||
var unique_pref = dirs.map{.split('/')}.abbrev.min_by{.len};
|
||||
var common_dir = [unique_pref, unique_pref.pop][0].join('/');
|
||||
say common_dir; # => /home/user1/tmp
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# maximal_initial_subarray takes as input an array of arrays:
|
||||
def maximal_initial_subarray:
|
||||
(map( .[0] ) | unique) as $u
|
||||
| if $u == [ null ] then []
|
||||
elif ($u|length) == 1
|
||||
then $u + ( map( .[1:] ) | maximal_initial_subarray)
|
||||
else []
|
||||
end ;
|
||||
|
||||
# Solution: read in the strings, convert to an array of arrays, and proceed:
|
||||
def common_path(slash):
|
||||
[.[] | split(slash)] | maximal_initial_subarray | join(slash) ;
|
||||
|
||||
common_path("/")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -s -f common_path.jq directories.txt
|
||||
"home/user1/tmp"
|
||||
Loading…
Add table
Add a link
Reference in a new issue