We had another nice question in a student activity today.
The increasing sequence of positive integers $a_1,a_2,a_3,\ldots$ has the property that
$$ a_{n+2}=a_n+a_{n+1} \text{ for all } n\ge 1. $$
If $a_7=120$, find $a_8$. (Solution: $a_8=194$.)
I found the RecurrenceTable
command and wrote:
seqs=Table[RecurrenceTable[{a[2 + n] == a[n] - a[1 + n], a[1] == 120,
a[2] == k}, a, {n, 1, 7}], {k, 1, 120}]
This produced a list of lists that are possible answers. How can I delete any list from seqs that contains a negative number? And if necessary, how can I delete any list from seqs that is not decreasing?
Also, if anyone else sees a nice way of solving this problem using Mathematica, I'd love to see your contribution.
DeleteCases[seqs, {___, _?Negative, ___}, {1}]
$\endgroup$Cases[seq, {_?NonNegative ..}]
$\endgroup$