{-
	LISTA DE EXERCÍCIOS LPG3

	ACADÊMICO: ESDRAS MAYRINK

	TURMA A
-}



{--- fatorial ----------------------------}
fat :: Int -> Int
fat 1 = 1
fat n = n * fat (n-1)

{--- Maior 3 -----------------------------}

max3 :: Int -> Int -> Int -> Int
max3 x y z
	| x >= y && x >= z = x
	| y >= x && y >= z = y
	| otherwise = z

{--- Potencia ----------------------------}

--função auxiliar...

isPar :: Int -> Bool
isPar x = (mod x 2 == 0)

pot x 0 = 1
pot 0 y = 0
pot x y
	| y < 0 = (1 / pot x (y * -1))
	| x < 0 && (isPar y) = pot (x * -1) (y)
	| otherwise = x * pot x (y-1)

{--- Parte Inteira Divisão ---------------}

isZero :: Int -> Bool
isZero x = (x == 0)

rstEda :: Int -> Int -> Int
rstEda x y
	| x < 0 && y < 0 = rstEda (x * -1) (y * -1)
	| x < 0 && y > 0 = -1 * rstEda (x * -1) y
	| x > 0 && y < 0 = -1 * rstEda x (y * -1)
	| x < y = 0
	| otherwise = 1 + rstEda (x - y) y

showRstEda :: Int -> Int -> String
showRstEda x y
	| isZero y = "Impossivel dividir por zero."
	| otherwise = "Parte inteira da divisao = " ++ show(rstEda x y)

{--- Resto Divisão -----------------------}

modEda :: Int -> Int -> Int
modEda x y
	| x < 0 && y < 0 = modEda (x * -1) (y * -1)
	| x < 0 && y > 0 = -1 * modEda (x * -1) y
	| x > 0 && y < 0 = -1 * modEda x (y * -1)
	| x < y = x
	| otherwise = modEda (x - y) y

showModEda :: Int -> Int -> String
showModEda x y
	| isZero y = "Impossivel dividir por zero."
	| otherwise = "Resto da divisao = " ++ show(modEda x y)


{--- Fibonacci --------------------------}


fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib x = (fib (x-1)) + (fib (x-2))
