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
| using System.Text.RegularExpressions; | |
| /* | |
| For this exercise, a word is any sequence of uppercase or lowercase characters from the Latin alphabet | |
| (A - Z, a - z). A sentence is a sequence of characters that ends with a period (.) or question mark (?). | |
| Write a program that reads a file input.txt and writes out all words that occur in at least two | |
| sentences. Ignore case: "Alice" and "alice" are the same word. Write the words in alphabetical order, | |
| one per line, all in lowercase. For each word, indicate how many sentences it occurs in. | |
| Your program should be reasonably efficient. (Specifically, if the input contains N distinct words, your | |
| program's expected running time should be less than O(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
| 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
| import Data.Char | |
| import Data.List | |
| search :: [String] -> [String] -> [Int] | |
| search grid = map (count . map toLower) | |
| where | |
| gridA = map (map toLower) grid | |
| gridB = transpose gridA | |
| line s = length . filter (s `isPrefixOf`) . tails |
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
| factors1 :: Integer -> Integer -> [Integer] | |
| factors1 k n | |
| | k * k > n = [n] | |
| | n `mod` k == 0 = k : factors1 k (n `div` k) | |
| | otherwise = factors1 (k + 1) n | |
| factors :: Integer -> [Integer] | |
| factors 1 = [] | |
| factors n = factors1 2 n |
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
| pos(P) :- member(P, [a,b,c,d]). | |
| next(go(P), [M, Box1, Box2, B], [P, Box1, Box2, B]) :- pos(M), pos(P). | |
| next(stack, [M, M, M, B], [M, box2, M, B]). | |
| next(unstack, [M, box2, M, B], [M, M, M, B]). | |
| next(push(box1, P), [M, M, Box2, B], [P, P, Box2, B]) :- pos(P). | |
| next(push(box2, P), [M, Box1, M, B], [P, Box1, P, B]) :- pos(P). | |
| next(climb_on_1, [M, Box1, Box2, B], [box1, Box1, Box2, B]) :- M = Box1; Box1 = box2, M = Box2. | |
| next(climb_off_1, [box1, Box1, Box2, B], [M, Box1, Box2, B]) :- pos(Box1), M = Box1; Box1 = box2, M = Box2. | |
| next(grab, [box1, box2, B, B], [box1, box2, B, hand]). |
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
| match_one(one(L), LIn, LOut) :- append(L, LOut, LIn). | |
| match_one(star(L), LIn, LOut) :- LIn = LOut; match_one(plus(L), LIn, LOut). | |
| match_one(plus(L), LIn, LOut) :- match_one(one(L), LIn, LMid), match_one(star(L), LMid, LOut). | |
| match_one(opt(L), LIn, LOut) :- LIn = LOut; match_one(one(L), LIn, LOut). | |
| match(Expr, Str) :- foldl(match_one, Expr, Str, []). | |
| decode_char(Key, A, B) :- B #= (A - 97 + Key) mod 26 + 97. | |
| decode_string(_, _, [], []). |
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). | |
| mines(Count, Mines) :- same_length(Count, Mines), append([[o],Mines,[o]], M), match(M, Count). |
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([], [], []). |
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) |
NewerOlder