Last active
August 29, 2015 14:17
-
-
Save lovasoa/64bf275fabfe17910347 to your computer and use it in GitHub Desktop.
Holà muchachos y muchachas, si esta la solutiones del ecercicos de es matinos.
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
#const n=3. | |
noeud(1..10). | |
arc(1,2).arc(1,3).arc(2,3).arc(2,4). | |
n{clique(X) : noeud(X)}n. | |
:- clique(X), clique(Y), not arc(X,Y), not arc(Y,X), X!=Y. | |
#show clique/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
data ExprA = Operateur (Int->Int->Int) ExprA ExprA | Nbr Int | |
evaluate:: ExprA -> Int | |
evaluate (Operateur f a b) = (evaluate a) `f` (evaluate b) | |
evaluate (Nbr a) = a | |
main = print $ evaluate $ Operateur (+) (Nbr 1) (Operateur (*) (Nbr 2) (Nbr 3)) |
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
data ExprA = Plus ExprA ExprA | Fois ExprA ExprA | Nbr Int deriving Show | |
evaluate:: ExprA -> Int | |
evaluate (Plus a b) = (evaluate a) + (evaluate b) | |
evaluate (Fois a b) = (evaluate a) * (evaluate b) | |
evaluate (Nbr a) = a | |
main = print $ evaluate $ Plus (Nbr 1) (Fois (Nbr 2) (Nbr 3)) |
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
nbrToL:: Int -> [Int] | |
nbrToL 0 = [] | |
nbrToL a = (nbrToL (a `div` 10)) ++ [a `rem` 10] | |
lToNbr:: [Int]->Int | |
lToNbr = foldl (\x n -> x*10+n) 0 | |
fusion:: Int->Int->Int | |
fusion long short | long > short = fusion short long | |
fusion small large = let (short, long) = (nbrToL small, nbrToL large) in | |
lToNbr $ (concat $ zipWith (\a b -> [a,b]) short long) | |
++ (drop (length short) long) | |
main = print $ fusion 123 123456 |
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
#const n=5. | |
#const k=3. | |
num(1..n). | |
ens(1..k). | |
1{dans(N,E) : ens(E)}1 :- num(N). | |
:- dans(N,E), dans(M,E), dans(M+N,E). | |
#show dans/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
triangle:: Int->Int | |
triangle n = head $ filter (>=10^(n-1)) [ k*(k+1) `div` 2 | k<-[0..] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment