def common_root(xs, root), do: common_root(xs, root, String.length(root))
def common_root([h | _] = xs, root \\ "", length \\ 0) do
newroot = elem(String.split_at(h, length + 1), 0)
if Enum.all?(xs, &String.starts_with?(&1, newroot)) do
common_root(xs, newroot, length + 1)
else
root
end
end