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
| public class FibonacciIterativo { | |
| public static long fibonacciIterativo(int n) { | |
| if (n <= 1) { | |
| return n; | |
| } | |
| long anterior = 0; | |
| long atual = 1; | |
| long temp = 0; |
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
| public class Fibonacci { | |
| public static int fib(int n) { | |
| if (n <= 1) { | |
| return n; | |
| } else { | |
| return fib(n - 1) + fib(n - 2); | |
| } | |
| } | |
| } |
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
| public class FatorialIterativo { | |
| public static int fatorialIterativo(int n) { | |
| int resultado = 1; | |
| for (int i = 1; i <= n; i++) { | |
| resultado *= i; | |
| } | |
| return resultado; | |
| } |
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
| public class Fatorial { | |
| public static int fatorial(int n) { | |
| if (n == 0 || n == 1) { | |
| return 1; | |
| } else { | |
| return n * fatorial(n - 1); | |
| } | |
| } | |
| } |
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
| module CountingSort where | |
| countingSort :: [Int] -> [Int] | |
| countingSort [] = [] | |
| countingSort ent = countingSortAux ent acum (n - 1) ret | |
| where | |
| n = length ent | |
| contagem = [contar (==i) ent | i <- [0 .. (maximum ent)]] | |
| acum = foldl (\x y -> if null x then [y] else x ++ [last x + y]) [] contagem | |
| ret = replicate n 0 |
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
| module Prova2 where | |
| --Questao 1 | |
| data ListaAninhada a = Elem a | Lista [ListaAninhada a] | |
| planificar :: ListaAninhada a -> [a] | |
| planificar (Elem a) = [a] | |
| planificar (Lista l) = concat $ map planificar l |
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
| {-# LANGUAGE NegativeLiterals #-} | |
| module Tipos where | |
| {- | |
| Questao 1 | |
| Semelhante à função somar, defina uma função de multiplicação recursiva para números | |
| naturais mult :: Nat -> Nat -> Nat. Dica: use a função somar definida no material de aula para os números naturais. | |
| -} |
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
| module Lib | |
| ( someFunc, getLine', putStr', putStrLn', putStr'', acumular, somador, somador2, obterLinha | |
| ) where | |
| import Text.Printf | |
| import System.IO | |
| someFunc :: IO () | |
| someFunc = putStrLn "someFunc" |
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
| module Lib | |
| ( reverso, converter, rotateLeft, removeMin, menor2, menor, escolheFuncoes, mapF | |
| ) where | |
| {- | |
| Questao 1 | |
| Implemente a função reverso :: [a] -> [a], que inverte a ordem dos elementos de uma lista. OBS: Não é permitido usar a função reverse da biblioteca padrão. | |
| Ex: reverso "abc" | |
| Main> "cba" |
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
| import java.util.Arrays; | |
| public class Quicksort { | |
| public static void ordenar(int[] vetor, int inicio, int fim) { | |
| if (inicio < fim) { | |
| int particao = particionar(vetor, inicio, fim); | |
| ordenar(vetor, inicio, particao - 1); | |
| ordenar(vetor, particao + 1, fim); | |
| } |
NewerOlder