Ingenious solution and beauty of simplicity

If I want the solution by code?