#include <core>
#include <console>

main()
    {
    enum (<<= 1) { A = 1, B, C, D, E, F, G }
    new nextstep[] =
        { C | E,     /* A can reach C and E */
          D | E,     /* B  "    "   D and E */
          G,         /* C  "    "   G */
          C | F,     /* D  "    "   C and F */
          0,         /* E  "    "   none */
          0,         /* F  "    "   none */
          E | F      /* G  "    "   E and F */
        }

    print("The departure point: ")
    new source = clamp( .value = toupper(getchar()) - 'A',
                        .min = 0,
                        .max = sizeof nextstep - 1
                      )

    print("^nThe number of steps: ")
    new steps = getvalue()

    /* make the set */
    new result = findtargets(source, steps, nextstep)
    printf("The points reachable from %c in %d steps: ", source+'A', steps)
    for (new i = 0; i < sizeof nextstep; i++)
        if (result & 1 << i)
            printf("%c ", i + 'A')
    }

findtargets(source, steps, nextstep[], numpoints = sizeof nextstep)
    {
    new result = 0
    new addedpoints = nextstep[source]
    while (steps-- > 0 && result != addedpoints)
        {
        result = addedpoints
        for (new i = 0; i < numpoints; i++)
            if (result & 1 << i)
                addedpoints |= nextstep[i]
        }
    return result
    }
