@PaulPanzer made a summary of existing answers here (including some they gave themselves).
I want to provide a clearer visualization for each of the existing solutions:
[Source code]Source code for the above program(https://puzzling.meta.stackexchange.com/a/7168/70545)