Working

Probably buggy, but rudimentary version is working.
Added heuristic explanation.