Skip to main content
3 of 3
Commonmark migration

Mathematica, 29 chars

{s}//.l_List:>(l⋃##&@@(l/.G))

Example:

G = {1 -> {2, 3}, 2 -> {3}, 3 -> {1}, 4 -> {2}}; s = 1;
{s}//.l_List:>(l⋃##&@@(l/.G))

{1, 2, 3}

alephalpha
  • 50k
  • 7
  • 68
  • 182