
For the above problem, we can write the recurrence relation, but we know that the 7th term equals 2. How can we work backwards to derive all possible values of the sequence from the 1st term to the 7th term?
Now, under the premise that I know the answer, all the cases generated by the first term of each sequence in the answer are shown in the following code:
rel = a[n] ==
Piecewise[{{3 a[n - 1] + 1, Mod[a[n - 1], 2] == 1}, {a[n - 1]/2,
Mod[a[n - 1], 2] == 0}}]
RecurrenceTable[{a[1] == #, rel}, a, {n, 7}] & /@ {128, 21, 20, 3}
