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 java.util.Iterator; | |
import java.util.List; | |
import java.util.ArrayList; | |
public class SomaPares { | |
public static List<Integer> somapares(List<Integer[]> pares) | |
{ | |
List<Integer> result = null; | |
if (pares != null) | |
{ |
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
let rec somapares l = | |
match l with | |
[] -> [] | |
| (a, b) :: rl -> (a+b) :: somapares rl | |
somapares [(1, 5); (4, 7)] |
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
let somapares l = List.map (fun (a,b) -> a+b) l in | |
somapares [(1, 5); (4,7)] |
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
let rec quick l = | |
match l with | |
[] -> [] | |
| [x] -> l | |
| p :: rl -> (match List.partition (fun x -> x < p) rl with | |
(l1, l2) -> (quick l1) @ [p] @ (quick l2)) |
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.List ( nub ) | |
import Data.Maybe ( fromJust ) | |
data Formula = Var String | And Formula Formula | | |
Or Formula Formula | Not Formula | |
getVarsDup (Var v) = [v] | |
getVarsDup (And f1 f2) = (getVarsDup f1) ++ (getVarsDup f2) | |
getVarsDup (Or f1 f2) = (getVarsDup f1) ++ (getVarsDup f2) | |
getVarsDup (Not f) = getVarsDup f |
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
let split s = | |
let l = String.length s in | |
let rec whitespace i = | |
if i >= l then [] else | |
if s.[i] = ' ' then whitespace (i+1) else nonws i 1 | |
and nonws i j = | |
if (i+j) = l then [(i,j)] else | |
if s.[i+j] = ' ' then (i,j) :: whitespace (i+j) else nonws i (j+1) in | |
List.map (fun (i, l) -> String.sub s i l) (whitespace 0) |
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
Ast.StExp (_loc, | |
(Ast.ExLet (_loc, Ast.ReNil, | |
(Ast.BiEq (_loc, (Ast.PaId (_loc, (Ast.IdLid (_loc, "f")))), | |
(Ast.ExFun (_loc, | |
(Ast.McArr (_loc, (Ast.PaId (_loc, (Ast.IdLid (_loc, "x")))), | |
(Ast.ExNil _loc), | |
(Ast.ExApp (_loc, | |
(Ast.ExApp (_loc, | |
(Ast.ExId (_loc, (Ast.IdLid (_loc, "*")))), | |
(Ast.ExId (_loc, (Ast.IdLid (_loc, "x")))))), |
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
print_tree(void). | |
print_tree(t(X, void, void)) :- write(X), !. | |
print_tree(t(X, L, R)) :- write('('), write(X), write(' '), print_tree(L), write(' '), print_tree(R), write(')'). |
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
/* p(Nome, Sobrenome, Brincadeira, Vitima) */ | |
gera(p(N, S, B, V)) :- | |
member(N, [ana, ester, pablo, rodolfo]), | |
member(S, [fontes, levis, matoso, salgado]), | |
member(B, [almofada, aranha, foto, mosca]), | |
member(V, [irmao, mae, pai, tia]). | |
dif(p(N1, S1, B1, V1), p(N2, S2, B2, V2)) :- | |
N1 \= N2, S1 \= S2, B1 \= B2, V1 \= V2. |
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
gera_cor(casa(C, _, _, _, _), [C], []) :- !. | |
gera_cor(casa(C, _, _, _, _), Cores, Resto) :- | |
select(C, Cores, Resto). |
OlderNewer