Skip to content

Instantly share code, notes, and snippets.

Abhinav Sarkar abhin4v

Block or report user

Report or block abhin4v

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sudoku-1-nextgrids.hs
nextGrids :: Grid -> (Grid, Grid)
nextGrids grid =
let (i, first@(Fixed _), rest) =
fixCell
. Data.List.minimumBy (compare `Data.Function.on` (possibilityCount . snd))
. filter (isPossible . snd)
. zip [0..]
. concat
$ grid
in (replace2D i first grid, replace2D i rest grid)
View sudoku-1-readgrid.hs
readGrid :: String -> Maybe Grid
readGrid s
| length s == 81 = traverse (traverse readCell) . Data.List.Split.chunksOf 9 $ s
| otherwise = Nothing
where
readCell '.' = Just $ Possible [1..9]
readCell c
| Data.Char.isDigit c && c > '0' = Just . Fixed . Data.Char.digitToInt $ c
| otherwise = Nothing
View sudoku-1-1.txt
+-------------------------------------+-------------------------------------+-------------------------------------+
| [123456789] [123456789] [123456789] | [123456789] [123456789] [123456789] | [123456789] 1 [123456789] |
| 4 [123456789] [123456789] | [123456789] [123456789] [123456789] | [123456789] [123456789] [123456789] |
| [123456789] 2 [123456789] | [123456789] [123456789] [123456789] | [123456789] [123456789] [123456789] |
+-------------------------------------+-------------------------------------+-------------------------------------+
| [123456789] [123456789] [123456789] | [123456789] 5 [123456789] | 4 [123456789] 7 |
| [123456789] [123456789] 8 | [123456789] [123456789] [123456789] | 3 [123456789] [123456789] |
| [123456789] [123456789] 1 | [123456789] 9 [123456789] | [123456789] [123456789] [123456789] |
+-------------------------------------+-------------------------------------+-------------------
@abhin4v
abhin4v / cache_server.exs
Created Mar 18, 2018
Simple cache using GenServer in Elixir
View cache_server.exs
defmodule CacheServer do
use GenServer
@name CS
## Client API
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, :ok, opts ++ [name: CS])
end
@abhin4v
abhin4v / pingpong.exs
Created Mar 17, 2018
PingPong in Elixir
View pingpong.exs
defmodule PingPong do
def ping(parent_pid) do
receive do
{_, _, 0} -> send parent_pid, :done
{pid, :pong, n} ->
IO.puts("ping: " <> Integer.to_string(n))
send pid, {self(), :ping, n-1}
ping parent_pid
end
end
@abhin4v
abhin4v / FileSort.hs
Last active Mar 14, 2018
Simple on-file number sort in haskell
View FileSort.hs
module Main where
import Data.List (sort)
import Data.List.Split (chunksOf)
import System.IO.Temp (writeSystemTempFile)
readI :: String -> Int
readI = read
merge :: (Ord a) => [a] -> [a] -> [a]
@abhin4v
abhin4v / json_parser.hs
Last active Feb 21, 2018
Simple JSON parser from scratch in Haskell
View json_parser.hs
module JSONParser where
import Control.Applicative (Alternative(..), optional)
import Control.Monad (replicateM)
import Data.Char (isDigit, isHexDigit, isSpace, isControl, chr, digitToInt)
import Data.Functor (($>))
import Data.List (intercalate)
newtype Parser i o = Parser { runParser :: i -> Maybe (i, o) }
@abhin4v
abhin4v / sudoku.hs
Last active Feb 6, 2018
Sudoku solver in Haskell
View sudoku.hs
import Control.Arrow ((&&&))
import Control.Applicative ((<|>))
import Control.DeepSeq (NFData(..))
import Control.Monad (foldM)
import Control.Parallel.Strategies (withStrategy, rdeepseq, parBuffer)
import Data.Bits
import Data.Char (isDigit, digitToInt)
import Data.Function (on)
import Data.List (nub, foldl', group, sort)
import Data.Maybe (isJust)
View keybase.md

Keybase proof

I hereby claim:

  • I am abhin4v on github.
  • I am abhin4v (https://keybase.io/abhin4v) on keybase.
  • I have a public key whose fingerprint is D2AA 0E12 9D4B 6D06 0FC6 4B22 7C91 66A6 F546 5AD5

To claim this, I am signing this object:

@abhin4v
abhin4v / transformers.hs
Last active Oct 22, 2017
An exploration of Monad Transformers in Haskell
View transformers.hs
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Transformers where
import Control.Applicative
import Control.Monad
import qualified Data.Char as Char
You can’t perform that action at this time.