# Generate a sequence of all cases

There is a sequence of numbers that satisfies
$$a_1=2$$, $$a_n-a_{n-1}\in \{1,3,5\}$$

I tried to enumerate all possibilities using the code below

n = 3;
NestList[Join @@ Outer[Plus, #, {1, 3, 5}] &, {{2}}, n - 1]


{{{2}}, {{3, 5, 7}}, {{4, 6, 8}, {6, 8, 10}, {8, 10, 12}}}

Now I hope to get such a list, is there an easy way?

{{2,3,4},{2,3,6},{2,3,8},{2,5,6},{2,5,8},{2,5,10},{2,7,8},{2,7,10},{2,7,12}}

## 2 Answers

Accumulate /@ Prepend[2] /@ Tuples[{1, 3, 5}, 2]

{{2, 3, 4}, {2, 3, 6}, {2, 3, 8}, {2, 5, 6}, {2, 5, 8}, {2, 5, 10}, >
{2, 7, 8}, {2, 7, 10}, {2, 7, 12}}


And, for fun:

ng = NestGraph[{1, 3, 5} + # &, 2, 2, VertexLabels -> Automatic]


root = 2;
sinks = VertexList[ng, _?(VertexOutDegree[ng, #] == 0 &)];

Join @@ (FindPath[ng, ##, Infinity, All] & @@@ Thread[{root, sinks}])

{{2, 3, 4}, {2, 5, 6}, {2, 3, 6}, {2, 7, 8}, {2, 5, 8}, {2, 3, 8},
{2, 7, 10}, {2, 5, 10}, {2, 7, 12}}

• Can we generate such a graph? i.sstatic.net/a8mKd.png NestGraph[{1,3,5}+#&,2,3,VertexLabels->Automatic] It doesn't work that way. Commented Jan 3, 2022 at 10:17
• @expression, I can't think of a simple way to get the graph in the link. You might want to post it as a new question with a brief explanation of the context.
– kglr
Commented Jan 3, 2022 at 13:53
FoldList[Plus, 2, #] & /@ Tuples[{1, 3, 5}, 2]