Skip to content

Instantly share code, notes, and snippets.

View vaibhavsagar's full-sized avatar
🕺
🪩

Vaibhav Sagar vaibhavsagar

🕺
🪩
View GitHub Profile

Keybase proof

I hereby claim:

  • I am vaibhavsagar on github.
  • I am vaibhavsagar (https://keybase.io/vaibhavsagar) on keybase.
  • I have a public key whose fingerprint is C358 4D99 C4E3 B6FF AE66 4BFC 1CE0 EE35 7CFB 9A10

To claim this, I am signing this object:

@vaibhavsagar
vaibhavsagar / sherlock_and_the_beast.hs
Last active September 8, 2016 13:35
Solution for code dojo 30/08/2016 with @miguel-vila
-- Slow solution that fails for n>19 due to integer overflow
import Data.List
import Data.Ord
maxPair n = sortBy (comparing snd) [(x,y) | x <- [0,3..n], y <- [0,5..(n-x)], x+y==n]
gen [] = -1
gen ((x,y):_) = let
noOf5s = (replicate x '5')
noOf3s = (replicate y '3')
in read (noOf5s ++ noOf3s) :: Int
@vaibhavsagar
vaibhavsagar / project-euler-12.hs
Created September 8, 2016 13:29
Code dojo solution for Week 4 with @sofiajeanne
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
@vaibhavsagar
vaibhavsagar / Week5.ipynb
Last active September 14, 2016 15:45
Week 5 code dojo solution with @phasedchirp
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vaibhavsagar
vaibhavsagar / Week6.ipynb
Created September 21, 2016 01:54
2016-09-20 solution with @satabdidas
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vaibhavsagar
vaibhavsagar / Week7.ipynb
Created September 27, 2016 21:25
hackerrank pairs code dojo with @sranso
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vaibhavsagar
vaibhavsagar / Week8.hs
Created October 6, 2016 15:52
Week 8 with @yuliaju
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
@vaibhavsagar
vaibhavsagar / Week10.hs
Created October 18, 2016 21:11
Week 10 with @zebesta
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
@vaibhavsagar
vaibhavsagar / Week11.hs
Created October 31, 2016 18:49
Week 11 code dojo with @MikeHeaton
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
@vaibhavsagar
vaibhavsagar / Week12.hs
Created November 1, 2016 21:51
Week 12 code dojo with @lamarqua
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]