Created
June 22, 2012 23:02
-
-
Save josejuan/2975694 to your computer and use it in GitHub Desktop.
Coordenadas de un número en una matriz caracol.
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
-- Cálculo dígito según coordenada en la matriz caracol. | |
-- Crédito de "jalonso" en: | |
-- http://www.solveet.com/exercises/Coordenadas-de-un-numero-en-una-matriz-caracol-/51/solution-326 | |
coordenadas n p | |
| p <= n = (1,p) | |
| p <= 2*n-1 = (p-n+1,n) | |
| p <= 3*n-2 = (n,3*n-1-p) | |
| p <= 4*n-4 = (4*n-2-p,1) | |
| otherwise = (x+1,y+1) | |
where (x,y) = coordenadas (n-2) (p-4*n+4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment