Está en la página 1de 1

import Data.

Char
import Data.List
funcion = do
putStr " Dame El Numero De la Tarjeta de Credito
"
a <- getLine
let b = fDigitos a
let x = validarTamao (length b)
putStrLn (x)
putStrLn ("entrada :
" ++ show (b))
let d = listaInvertida b
putStrLn( "lista al reves " ++ show (d))
let e = funcionIndices d
let c = doblesdeLista d e
putStrLn("dobles de los numeros : " ++ show (c))
let f = sumadelista c
putStrLn("suma De La Lista : " ++ show(f))
putStrLn("El Numero : "++ impresion 0 b ++ " " ++ (modulo (fromIntegral
(f`mod`10))))
impresion :: Int -> [Int] -> [Char]
impresion n b | n >= 0 && n <=3 = show (b !! n) ++ impresion (n+1) b
| n == 4 = " " ++ show (b !! n) ++ impresion (n+1) b
| n>=5 && n<=7 = show (b !! n) ++ impresion (n+1) b
| n == 8 = " " ++ show (b !! n) ++ impresion (n+1) b
| n >=9 && n<=11 = show (b !! n) ++ impresion (n+1) b
| n == 12 = " " ++ show (b !! n) ++ impresion (n+1) b
| n <= 15 = show (b !! n) ++ impresion (n+1) b
| otherwise = []
validarTamao :: Int -> [Char]
validarTamao n | n == 16 = "Entrada Valida Puede Continuar"
| otherwise = error "Entrada Invalida faltan digitos o s
obran digitos"
modulo :: Integer -> [Char]
modulo 0 = " Es valido para usarlo en una tarjeta de credito"
modulo _ = " Es Invalido pruebe de Nuevo"
quitaEs :: [Char]->[Char]
quitaEs a = [c | c <- a, c /= ' ']
fDigitos :: [Char] -> [Int]
fDigitos a = map digitToInt (quitaEs a)
listaInvertida :: [Int]->[Int]
listaInvertida a = reverse a
funcionIndices :: [Int] -> [Int]
funcionIndices d = findIndices (`elem` [0..9]) d
doblesdeLista :: [Int] -> [Int] -> [Int]
doblesdeLista d listadeindices = [ if (((c+1) `mod` 2)==0) then ((d !! c)*2) els
e (d !! c) | c <- listadeindices]
sumadelista :: [Int] -> Int
sumadelista c = sum ([ if (x>10) then sum(map digitToInt(show x)) else x| x<-c])

También podría gustarte