-
-
Save cesarkawakami/064d59c24446653ae1d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import math | |
m = [ | |
[1, 2, 4, 7, 11, 16], | |
[3, 5, 8, 12, 17], | |
[6, 9, 13, 18], | |
[10, 14, 19], | |
[15, 20], | |
[21], | |
] | |
def inv(k): | |
x = int((math.sqrt(8 * k - 7) + 1) / 2) | |
y = k - x * (x - 1) / 2 | |
x -= y - 1 | |
return x, y | |
for row in m: | |
print "\t".join(str(inv(k)) for k in row) |
This file contains hidden or 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
(1, 1) (2, 1) (3, 1) (4, 1) (5, 1) (6, 1) | |
(1, 2) (2, 2) (3, 2) (4, 2) (5, 2) | |
(1, 3) (2, 3) (3, 3) (4, 3) | |
(1, 4) (2, 4) (3, 4) | |
(1, 5) (2, 5) | |
(1, 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment