Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created February 4, 2010 05:23
Show Gist options
  • Save jsoffer/294346 to your computer and use it in GitHub Desktop.
Save jsoffer/294346 to your computer and use it in GitHub Desktop.
data Estado = N | S | E | W deriving (Show, Eq)
d n = div n 2
dd n = div (n-1) 2
du n = div (n+1) 2
paso :: (Estado, Integer) -> (Estado, Integer)
paso (e, 0) = (e, 0)
paso (N, x)
| even x = paso (W, 3 * (d x))
| odd x = paso (W, dd x)
paso (S, x)
| even x = paso (E, 3 * (d x))
| odd x = paso (N, du x)
paso (E, x)
| even x = paso (E, 3 * (d x))
| odd x = paso (N, du x)
paso (W, x)
| even x = paso (N, d x)
| odd x = paso (S, dd x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment