Java program to identify patterns in numbers
I would suggest to build state machine:
A. Initialization with patterns:
- Normalize all patterns
- Build a tree with depth = 6 that represents all patterns starting from root and all possible choices on every depth.
B. Run state machine
A.1. Pattern normalization.
A A A A A A => A0 A0 A0 A0 A0 A0
C A C A C A => A0 B0 A0 B0 A0 B0 (always start with A, and then B, C, D, etc.)
B B+1 B+2 A A+1 A+2 => A0 A1 A2 B0 B1 B2
Thus, you always have normalized pattern start with A0.
A.2. Build a tree
1. A0
/ | \
2. A0 B0 A1
| | |
3. A0 A0 A2
| | |
4. A0 B0 B0
| | |
5. A0 A0 B1
| | |
6. A0 B0 B2
| | |
p1 p2 p3
B. Run state machine
Use Depth-first search algorithm using recursion to find matched pattern.
Does it make sense?