Skip to content

Instantly share code, notes, and snippets.

@washingtonsoares
Created March 31, 2016 00:53
Show Gist options
  • Save washingtonsoares/af15fcff6aac63445261e370ff192896 to your computer and use it in GitHub Desktop.
Save washingtonsoares/af15fcff6aac63445261e370ff192896 to your computer and use it in GitHub Desktop.
iguais :: (Int, Int, Int)-> Int
iguais (x, y, z)
| x == y && y == z = 3
| x == y || x == z || y == z = 2
| otherwise = 0
modiv :: Int -> Int -> (Int, Int)
modiv x y = (div x y, mod x y)
distancia :: (Float, Float)-> (Float, Float)-> Float
distancia (x1, x2) (y1, y2) = sqrt(((x2-x1)^2) + ((y2-y1)^2))
local :: (Float, Float, Float)-> (Float, Float) -> String
local (xc, yc, raio) (xp, yp)
| distancia (xp, yp) (xc, yc) > raio = "Ponto fora do circulo"
| distancia (xp, yp) (xc, yc) == raio = "Ponto no contorno do circulo"
| otherwise = "Ponto dentro do circulo"
mesmos :: (Int, Int)-> (Int, Int)-> Bool
mesmos (x1, y1)(x2, y2) = (x1 == x2 || x1 == y2) && (y1 == x2 || y1 == y2)
fun1 :: Int -> Int -> (Int ,Int)
fun1 x y
| x > y = (x ,1)
| x < y = (y ,1)
| otherwise = (x ,2)
fun2 :: Int -> Int -> Int -> (Int ,Int)
fun2 x y z
| fst (fun1 x y) > z = fun1 x y
| fst (fun1 x y) == z = (z, (snd (fun1 x y)) + 1)
| fst (fun1 x y) < z = (z ,1)
-- saida : (6, 1)
separa1 :: (String, Char)->(String, Char)->(String, Char)->((String, String, String),(Char, Char, Char))
separa1 (x1, x2)(y1, y2)(z1, z2) = ((x1, y1, z1),(x2, y2, z2))
separa2 :: (String, Char)->(String, Char)->(String, Char)->((String, String, String),(Char, Char, Char))
separa2 parx pary parz = ((fst parx, fst pary, fst parz), (snd parx, snd pary, snd parz))
bissexto :: Int-> Bool
bissexto x
| (mod x 400 == 0) = True
| (mod x 4 == 0) && (mod x 100 /= 0) = True
| otherwise = False
valida :: (Int, Int, Int)-> Bool
valida (dia, mes, ano)
| mes == 1 && (dia >= 1 && dia <= 31) = True
| mes == 2 && (dia >= 1 && (dia <= 28 || (dia <= 29 && bissexto ano))) = True
| mes == 3 && (dia >= 1 && dia <= 31) = True
| mes == 4 && (dia >= 1 && dia <= 30) = True
| mes == 5 && (dia >= 1 && dia <= 31) = True
| mes == 6 && (dia >= 1 && dia <= 30) = True
| mes == 7 && (dia >= 1 && dia <= 31) = True
| mes == 8 && (dia >= 1 && dia <= 31) = True
| mes == 9 && (dia >= 1 && dia <= 30) = True
| mes == 10 && (dia >= 1 && dia <= 31) = True
| mes == 11 && (dia >= 1 && dia <= 30) = True
| mes == 12 && (dia >= 1 && dia <= 31) = True
| otherwise = False
-- >snd (fst ((True, 4), "Bom")) SAIDA: 4
-- >fst ((True, 'a'), 7) SAIDA: (True, 'a')
-- >snd (snd ((True, 4), (False, 7))) SAIDA: 7
media :: (String, Float, Float, Float) -> (String, Float)
media (nome, p1, p2, p3) = (nome, (p1+p2+p3)/3)
eh_aprovado :: (String, Float, Float, Float) -> (String, String)
eh_aprovado (nome, p1, p2, p3) = if (snd(media (nome, p1, p2, p3)) >= 60) then (nome, "Aprovado")
else (nome, "Reprovado")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment