Attempt at temporal pattern recognition algorithm