Skip to content

Instantly share code, notes, and snippets.

@rbtnn
Last active August 29, 2015 14:08
Show Gist options
  • Save rbtnn/c25f826c6e19f432f586 to your computer and use it in GitHub Desktop.
Save rbtnn/c25f826c6e19f432f586 to your computer and use it in GitHub Desktop.
function! s:hoge(xs)
let top = get(a:xs,0,[])
let rest = a:xs[1:]
let i = 0
while i < len(rest)
for e in top
if -1 < index(get(rest,i,[]), e)
let top = uniq(sort(top + rest[i]))
call remove(rest,i)
let i = -1
break
endif
endfor
let i += 1
endwhile
if 1 < len(rest)
return [top] + s:hoge(rest)
else
return [top] + rest
endif
endfunction
echo s:hoge([[1,3],[3,4],[3,5],[5,6],[3,8],[9],[0],[4,11]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment