Skip to content

Instantly share code, notes, and snippets.

View ashutoshmehra's full-sized avatar

Ashutosh Mehra ashutoshmehra

View GitHub Profile
### Keybase proof
I hereby claim:
* I am ashutoshmehra on github.
* I am ashutoshmehra (https://keybase.io/ashutoshmehra) on keybase.
* I have a public key whose fingerprint is 366E 3FD5 75AC 22ED 9F5C 585D BB39 438B E008 71D6
To claim this, I am signing this object:
@ashutoshmehra
ashutoshmehra / sudoku.hs
Created August 13, 2009 19:02
Peter Norvig's beautiful Python program (http://norvig.com/sudoku.html) now in Haskell!
-- Peter Norvig's beautiful Python program (http://norvig.com/sudoku.html)
-- that uses constraint propagation (and ultimately searching)
-- to solve Sudoku instances
--
-- Now in everybody's favorite language!
-- Haskell coding by Ashutosh Mehra (http://ashutoshmehra.net/blog/)
import List (elem, nub, filter, delete, intersperse, replicate)
import Data.Map (Map, fromList, (!), insert, keys, elems, toList)
import Data.List (intercalate)
/* Solves the puzzle: Puzzle: recursive postfix evaluation.
Ref: http://rgrig.blogspot.com/2009/03/postfix-expressions.html
*/
#include <stdio.h>
#define F 0x40
char eval(int * pr) {
char ch;
int val;
switch((ch = getchar())) {
@ashutoshmehra
ashutoshmehra / gist:93143
Created April 10, 2009 16:15
2-space indents, never tabs
(setq-default c-basic-offset 2)
(setq-default indent-tabs-mode nil)
@ashutoshmehra
ashutoshmehra / gist:93142
Created April 10, 2009 16:13
indents are to be real tab character worth 8-space
(dir-locals-set-class-variables
'beautiful-code
'((c++-mode . ((c-basic-offset . 8)
(tab-width . 8)
(indent-tabs-mode . t)))))
(dir-locals-set-directory-class
"d:/work/BeautifulCode/" 'beautiful-code)
@ashutoshmehra
ashutoshmehra / MemoFib.hs
Created March 17, 2009 12:50
Memoized Fibonacci using GHC's inline (code from AndyGill's blog post)
-- Code from: http://blog.unsafeperformio.com/?p=34
module Main where
import GHC.Exts
type Nat = Int
memo :: (Nat -> Integer) -> [Integer]
memo f = map f [0..]
apply :: [Integer] -> (Nat -> Integer)
apply xs n = xs !! n