Explanation

 

How it works

 

How to implement