RosettaCodeData/Task/Find-common-directory-path/Picat/find-common-directory-path-2.picat
2023-07-01 13:44:08 -04:00

16 lines
363 B
Text

find_common_directory_path2(Dirs) = Path =>
common_prefix2(Dirs,Path,'/',_Len).
table(+,-,max)
common_prefix2(Ls,Prefix,Len) =>
common_prefix2(Ls,Prefix,[],Len).
table(+,-,+,max)
common_prefix2(Ls,Prefix,Last,Len) =>
foreach(L in Ls)
append(Prefix,_,L)
end,
if Last != [], Prefix != [] then
Prefix.last() == Last
end,
Len = Prefix.length.