Green flag, you know that, did I?
You can see this algorithm in this project: https://scratch.mit.edu/projects/69092586/