Skip to content

Instantly share code, notes, and snippets.

@josejuan
Created June 22, 2012 23:02
Show Gist options
  • Save josejuan/2975694 to your computer and use it in GitHub Desktop.
Save josejuan/2975694 to your computer and use it in GitHub Desktop.
Coordenadas de un número en una matriz caracol.
-- 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