Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created February 3, 2015 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseanpg/c254aa60adba32f8a829 to your computer and use it in GitHub Desktop.
Save joseanpg/c254aa60adba32f8a829 to your computer and use it in GitHub Desktop.
@Jose_A_Alonso Exercitium: Mayor capicúa producto de dos números de n cifras
-- www.glc.us.es/~jalonso/exercitium/mayor-capicua-producto-de-dos-numeros-de-n-cifras
mayorCapicuaP n = alpha 0 (t-1)
where
t = 10^n
b = div t 10
alpha a x | x > b = let a' = case beta x of
Just z -> max z a
Nothing -> a
in alpha a' (x-1)
| otherwise = a
where
beta y | y > b = let z = x*y
s = show z
in case s == reverse s of
True -> Just z
False -> beta (y-1)
| otherwise = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment