filtering directly and indirectly connected things from list

Posted by Andreas Romeyke on Stack Overflow See other posts from Stack Overflow or by Andreas Romeyke
Published on 2010-03-15T08:53:21Z Indexed on 2010/03/15 8:59 UTC
Read the original article Hit count: 315

Filed under:
|
|
|
|

Hello,

if you have a function "test a b" which returns true if a and b are connected directly and if you have a given unordered list of things, what would be an elegant and fast solution to filter all connected things from given list?

Example:

let test a b = let diff = a - b in diff == 0 ;;

let lst = [4;1;7;3;8;9;2;0] ;;

filter_connected 2 lst ;;

-> [4;1;3;2;0]

Any hints?

© Stack Overflow or respective owner

Related posts about ocaml

Related posts about list