Algorithm to identify if a string of numbers is a lottery sequence
I'm not sure if I understood your solution or not. But it seems that 78 also is included in the last sequence.

Here is my answer:
For any valid sequence $w$ ($w$ is valid iff $7\le n\le14$ where $n$ is the size of $w$) there should be $n-7$ pairs and $14-n$ single numbers ($14-n+n-7=7)$. We run a recursive function:


Setup the memory: $A$ count of pairs and $B$ count of single numbers in the sequence
If $w[0]$ is equal or less than 5, then there are two possibilities:


It can be a single member if $B&lt;14-n$
It can be combined with the next number if $A&lt;n-7$


If neither of these cases is valid, this sequence is not valid
If $w[0]$ is greater than 5, then it can not be combined with the next number. If $A\ge n-7$ then this sequence is not valid.


Then run the same algorithm for the sequence following $w[0]$ (or $w[1]$ for case 1.1).

For example $w=12345678$


$\{1\}$ and $\{12\}$
$\{1,2\}$, $\{1,23\}$, $\{12,3\}$
$\{1,2,3\}$, $\{1,2,34\}$,$\{1,23,4\}$, $\{12,3,4\}$
$\{1,2,3,4\}$, $\{1,2,3,45\}$, $\{1,2,34,5\}$, $\{1,23,4,5\}$, $\{12,3,4,5\}$
$\{1,2,3,4,5\}$,$\{1,2,3,4,56\}$,$\{1,2,3,45,6\}$,$\{1,2,34,5,6\}$,$\{1,23,4,5,6\}$,$\{12,3,4,5,6\}$
$\{1,2,3,4,5,6\}$,$\{1,2,3,4,5,67\}$,$\{1,2,3,4,56,7\}$,$\{1,2,3,45,6,7\}$,$\{1,2,34,5,6,7\}$,$\{1,23,4,5,6,7\}$,$\{12,3,4,5,6,7\}$
$\{1,2,3,4,5,6,7\}$,$\{1,2,3,4,5,67,8\}$,$\{1,2,3,4,56,7,8\}$,$\{1,2,3,45,6,7,8\}$,$\{1,2,34,5,6,7,8\}$,$\{1,23,4,5,6,7,8\}$,$\{12,3,4,5,6,7,8\}$


all the sequences ended with $8$ are valid.