
Recent Posts
Recent Comments
Archives
Categories
Meta
Advertisements
import Data.List wordFinderHelper reverseword content = foldl step (0,[],1,””) content where step (x,ys,i,matcher) c  c:matcher == reverseword = ((x+1),ilength reverseword:ys,i+1,””)  (c:matcher) `isSuffixOf` reverseword = (x,ys,i+1,c:matcher)  otherwise = (x,ys,i+1,””) wordFinder word content = (\(x,y,_,_)> (x,reverse y))$wordFinderHelper (reverse word) … Continue reading
wordFilnderHelper word content = foldl step (0,[],0) $ words content where step (x,y,z) w  word == w = ((x+1),z:y,z+1)  otherwise = (x,y,z+1) wordFinder word content = (\(x,y,z)>(x,reverse y))$wordFilnderHelper word content –sample run wordFinder “hello” “hello this is tough … Continue reading
Merge sort explanation http://en.wikipedia.org/wiki/Merge_sort mergeSort xs = merge (split xs) [] where split [] = [] split (x:xs) = [x]:split xs merge [] [] = [] merge (x:x1:xs) ys = merge xs ((sort x x1):ys) merge [x] ys = merge … Continue reading
fib = lazyFib 1 1lazyFib x y = x:lazyFib y (x+y)fibNth n = head$drop (n1)$fib –sampe run take 10 fib [1,1,2,3,5,8,13,21,34,55] fibNth 100354224848179261915075
–For details of Pascal’s_triangle go through : http://en.wikipedia.org/wiki/Pascal’s_triangle — Haskell is good at lazy evaluation ,Using that here is infinite Pascal’s_triangle pascalTriangle = lazyPascaltriangle [1] lazyPascaltriangle xs = xs : lazyPascaltriangle((head xs):pairSum xs) where pairSum [] = [] pairSum [x] … Continue reading
myreverse xs = reverseHelper xs [] where reverseHelper (x:xs) ys = reverseHelper xs (x:ys) reverseHelper [] ys = ys –sample myreverse [1,2,3] [3,2,1] myreverse “hello” “olleh” another way with (++) infixr reverse x:xs = reverse xs ++ [x] reverse [x] … Continue reading
— tree structure PTree a = Pleaf a  PNode (PTree a) (PTree a) –mirror mirror (Pleaf a) = Pleaf a mirror (PNode n1 n2) = PNode(mirror n1) (mirror n2)