Message Boards Message Boards

GROUPS:

Functional and/or Built-ins to accomplish this partly procedural algorithm?

Posted 24 days ago
190 Views
|
2 Replies
|
1 Total Likes
|

2 Replies

Copy-paste on your example is not so easy. Please post code rather than images or the like.

Based on the example, I believe the method below will do what you have in mind.

Table[
 Flatten[Outer[List, connectedComponents[[j]], 
   Apply[Join, Delete[connectedComponents, j]]], 1], {j, 
  Length[connectedComponents]}]

(* Out[1548]= {{{a, e}, {a, f}, {a, g}, {a, h}, {a, i}, {b, e}, {b, 
   f}, {b, g}, {b, h}, {b, i}, {c, e}, {c, f}, {c, g}, {c, h}, {c, 
   i}, {d, e}, {d, f}, {d, g}, {d, h}, {d, i}}, {{e, a}, {e, b}, {e, 
   c}, {e, d}, {e, h}, {e, i}, {f, a}, {f, b}, {f, c}, {f, d}, {f, 
   h}, {f, i}, {g, a}, {g, b}, {g, c}, {g, d}, {g, h}, {g, i}}, {{h, 
   a}, {h, b}, {h, c}, {h, d}, {h, e}, {h, f}, {h, g}, {i, a}, {i, 
   b}, {i, c}, {i, d}, {i, e}, {i, f}, {i, g}}} *)

Thank you Daniel, this is an eye-opener on how to use List or other Heads as the function in Outer and mapping operations.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract