Created
February 3, 2015 23:13
-
-
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
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
-- 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