{{ message }}

Instantly share code, notes, and snippets.

# Vaibhav Sagar vaibhavsagar

🕺
🌐
Created Nov 7, 2016
Cute interview question solution
View expressionmatch.hs
 import qualified Data.Map.Strict as Map import Data.List (inits, tails, any) match "" "" _ = True match "" _ _ = False match _ "" _ = False match expr text matches = let possibilities = zip (tail \$ inits text) (tail \$ tails text) pattern = head expr expr' = tail expr
Created Nov 1, 2016
Week 12 code dojo with @lamarqua
View Week12.hs
 import Control.Applicative import Control.Monad import System.IO import Data.List (foldl') import Data.Maybe main :: IO () main = do t <- fmap read getLine :: IO Int lns <- mapM (const getLine) [1..t]
Created Oct 31, 2016
Week 11 code dojo with @MikeHeaton
View Week11.hs
 import qualified Data.Map.Strict as Map import qualified Data.Set as Set import Data.Map.Strict ((!)) import Data.List (partition) getNeighbours list i j = let possible = [(i-1, j-1),(i-1, j), (i-1, j+1), (i, j-1), (i, j+1), (i+1, j-1), (i+1, j), (i+1, j+1)] actual = filter (\(x, y) -> x >=0 && y >= 0 && x < length list && y < length (head list)) possible
Created Oct 18, 2016
Week 10 with @zebesta
View Week10.hs
 sherlock :: Int -> Int -> Int -> [Int] -> Bool sherlock left current sm [] = if left == sm then True else False sherlock left current sm rest = case compare left sm of LT -> let left' = left + current
Created Sep 8, 2016
Code dojo solution for Week 4 with @sofiajeanne
View project-euler-12.hs
 import Control.Monad.Trans.State import Data.Map.Strict as Map import Data.Set as Set triangle n = sum [1..n] factors n = [f | f <- [1..n], n `mod` f == 0 ] addFactors :: Int -> Int -> Map.Map Int (Set.Set Int) -> Map.Map Int (Set.Set Int) addFactors n i factorMap | n == i = Map.insert n (Set.fromList (factors n)) factorMap
Created Oct 6, 2016
Week 8 with @yuliaju
View Week8.hs
 import Data.List (groupBy, sortBy) import Data.Ord (comparing) data DisjointSet = DisjointSet {index :: Int, value :: Int, parent :: Int} deriving Show find :: [DisjointSet] -> Int -> Int find ls i = let djs = ls !! (i - 1) ix = index djs p = parent djs
Created Sep 27, 2016
hackerrank pairs code dojo with @sranso
View Week7.ipynb
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Created Sep 21, 2016
2016-09-20 solution with @satabdidas
View Week6.ipynb