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 Main where | |
| import Control.Monad | |
| import Data.List | |
| import Data.Maybe | |
| modifyAt :: Int -> (a -> a) -> [a] -> [a] | |
| modifyAt pos f l = ll ++ case lr of | |
| [] -> [] | |
| x:xs -> f x:xs |
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 Data.List | |
| data Prop | |
| = Const Bool | |
| | Var Char | |
| | Not Prop | |
| | And Prop Prop | |
| | Or Prop Prop | |
| deriving (Show) |
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 Data.Function | |
| class Queue q where | |
| emptyQueue :: q a | |
| isEmpty :: q a -> Bool | |
| enqueue :: a -> q a -> q a | |
| dequeue :: q a -> (a, q a) | |
| data SQueue a = SQ [a] [a] |
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 Tree = Nil | Node Tree Int Tree deriving (Eq, Ord, Show) | |
| allBalanced :: Int -> [Tree] | |
| allBalanced = go 1 | |
| where | |
| go from to | |
| | from > to = [Nil] | |
| | otherwise = [Node l x r | x <- [h .. h + m], l <- go from (x - 1), r <- go (x + 1) to] | |
| where | |
| (h, m) = (from + to) `divMod` 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
| import Data.List | |
| is_equiv :: (a -> a -> Bool) -> [a] -> Bool | |
| is_equiv (~=) set = refl && sym && trans | |
| where | |
| infix 1 ==> | |
| x ==> y = not x || y | |
| every c = all c set |
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
| factors_ :: Int -> Int -> [Int] | |
| factors_ p k = | |
| if k * k > p | |
| then [p] | |
| else if p `mod` k == 0 | |
| then k:factors_ (p `div` k) k | |
| else factors_ p (k + 1) | |
| factors :: Int -> [Int] | |
| factors p = factors_ p 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
| mark_enter(X, enter(X)). | |
| dfs(_, [], Visited, Visited, Time, Time). | |
| dfs(G, [exit(V)|Vs], Visited, FinalVisited, Time, FinalTime) :- | |
| member(V/_/Time, Visited), NewTime is Time + 1, | |
| dfs(G, Vs, Visited, FinalVisited, NewTime, FinalTime). | |
| dfs(G, [enter(V)|Vs], Visited, FinalVisited, Time, FinalTime) :- | |
| ( member(V/_/_, Visited) -> dfs(G, Vs, Visited, FinalVisited, Time, FinalTime) | |
| ; member(V-Neigh, G), maplist(mark_enter, Neigh, NeighEnter), | |
| NewTime is Time + 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
| maptree(_, nil). | |
| maptree(P, b(L, X, R)) :- | |
| call(P, X), maptree(P, L), maptree(P, R). | |
| size(nil, 0, -1). | |
| size(b(L, _, R), S, H) :- | |
| SP is S - 1, between(0, SP, SL), SR is S - SL - 1, | |
| HP is H - 1, (HL = HP, between(-1, HP, HR); between(-1, HP, HL), HR = HP, HL \= HR), | |
| size(L, SL, HL), | |
| size(R, SR, HR). |
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
| cone([o,o,o], 0). | |
| cone(R, 1) :- select(x, R, [o,o]). | |
| cone(R, 2) :- select(o, R, [x,x]). | |
| cone([x,x,x], 3). | |
| match([_,_], []). | |
| match([A,B,C|R], [M|RM]) :- cone([A,B,C],M), match([B,C|R], RM). | |
| miny(Pocty, Miny) :- same_length(Pocty, Miny), append([[o],Miny,[o]], MinyLong), match(MinyLong, Pocty). |
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
| sublist(L, M) :- | |
| M = [_|_], | |
| append(_, Suffix, L), | |
| append(M, _, Suffix). | |
| subseq([], []). | |
| subseq([X|L], [X|M]) :- subseq(L, M). | |
| subseq([_|L], M) :- subseq(L, M). | |
| disjoint([], [], []). |
NewerOlder