Created
May 7, 2016 05:06
-
-
Save Charlyzzz/a89269fa78c9087388e8cff86e7c3a4f to your computer and use it in GitHub Desktop.
Corrección de Eric
This file contains 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
import Data.Char | |
instance Show (a -> b) where | |
show a= "<function>" | |
diccionario = ["aaron", "abaco", "abecedario", "baliente", "beligerante"] | |
type Usuario = (String, String) | |
type Aplicacion = ([Usuario], [(String->Bool)], (String -> String)) | |
bancoNacion = ([("juan","sdsdiulwd"), ("robby","sxwrhotxhlhh")], [tieneAlMenosUnNumero,tieneXMayusculas 0], textoCesar 5) | |
empiezaConLetra :: String -> String -> Bool | |
empiezaConLetra = empiezaCon | |
{- | |
empiezaConLetra letra = letra == . head | |
-} | |
empiezaCon :: String -> String -> Bool | |
empiezaCon palabra1 palabra2 = take (length palabra2) palabra1 == palabra2 | |
tieneAlMenosUnNumero :: String -> Bool | |
tieneAlMenosUnNumero = not.(==0).length.filter isDigit | |
{- | |
tieneAlMenosUnNumero = any isDigit | |
-} | |
tieneXMayusculas :: Int -> String -> Bool | |
tieneXMayusculas x = (==x).length.filter isUpper | |
esIndeducible :: String -> Bool | |
esIndeducible contrasena = ((==0).length.filter (contieneA contrasena)) diccionario | |
{- | |
esIndeducible contrasena = (not . any (contieneA contrasena)) diccionario | |
-} | |
contieneA :: String -> String -> Bool | |
contieneA "" _ = False | |
contieneA palabra1 palabra2 | empiezaCon palabra1 palabra2 = True | |
| otherwise = contieneA (tail palabra1) palabra2 | |
{- | |
Quizás te sirve expresar palabra2 como c:cs | |
-} | |
puedoUsar :: Aplicacion -> String -> Bool | |
puedoUsar (_, listaFunciones, _) = aplicarFunciones listaFunciones | |
aplicarFunciones :: [(String->Bool)] -> String -> Bool | |
aplicarFunciones listaFunciones contrasena = foldl (flip (aplicarFuncion contrasena)) True listaFunciones | |
{- | |
foldl1 | |
-} | |
aplicarFuncion :: String -> (String -> Bool) -> (Bool -> Bool) | |
aplicarFuncion contrasena funcion = (&&) (funcion contrasena) | |
textoCesar :: Int -> String -> String | |
textoCesar n = map (\x -> toEnum ((fromEnum x)+n)) | |
{- | |
textoCesar n = map (toEnum . + n . fromEnum x ) | |
-} | |
textoHash :: String -> Int | |
textoHash = sum.map (\x -> fromEnum x) | |
{- | |
textoHash = sum.map fromEnum x | |
-} | |
registrarse :: Usuario -> Aplicacion -> Aplicacion | |
registrarse (nombre, contrasena) (listaUsuarios, listaFunciones, encriptar) | puedoUsar (listaUsuarios, listaFunciones, encriptar) contrasena = agregarUsuario (nombre, contrasena) (listaUsuarios, listaFunciones, encriptar) | |
| otherwise = (listaUsuarios, listaFunciones, encriptar) | |
agregarUsuario :: Usuario -> Aplicacion -> Aplicacion | |
agregarUsuario (nombre, contrasena) (listaUsuarios, listaFunciones, encriptar) = (listaUsuarios ++ [(nombre, encriptar contrasena)], listaFunciones, encriptar) | |
--paradgima = ([], [tieneMasDeNCaracteres 6, not empiezaConLetra "t"], textoCesar 4) | |
{- | |
Debería estár hecho | |
-} | |
facebutt = map (\x -> ("usuario" ++ show x, textoHash ("lalaPasswordDificil" ++ show x))) [1..] | |
--si, ya que puedo usar solo evalua la lista de funciones, siempre devolvera True | |
--si, se agregara el usuario por el mismo motivo que arriba | |
{- | |
Facebutt no te tipa | |
-} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment