-
-
Save TorD/08f971dceebc85580108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Efficiently make a grid coordinate out of a flat integer size, with the limit set to 2 per row | |
# Change occurence of 2 in method to change limit per row | |
def grid_size(size) | |
Array.new(size){|n| [n % 2, n / 2]} | |
end | |
# Example return | |
grid_size(6) => [[0, 0], [1, 0], [0, 1], [1, 1], [0, 2], [1, 2]] | |
# Or in more readable return format | |
[[0, 0], [1, 0], | |
[0, 1], [1, 1], | |
[0, 2], [1, 2]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment