Skip to content

Instantly share code, notes, and snippets.

Avatar

Ashutosh Mehra ashutoshmehra

View GitHub Profile
View gist:0d26f6a831f60685d6b4
### 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 Aug 13, 2009
Peter Norvig's beautiful Python program (http://norvig.com/sudoku.html) now in Haskell!
View sudoku.hs
-- 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)
View recursive_postfix_eval.c
/* 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 Apr 10, 2009
2-space indents, never tabs
View gist:93143
(setq-default c-basic-offset 2)
(setq-default indent-tabs-mode nil)
@ashutoshmehra
ashutoshmehra / gist:93142
Created Apr 10, 2009
indents are to be real tab character worth 8-space
View gist:93142
(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 Mar 17, 2009
Memoized Fibonacci using GHC's inline (code from AndyGill's blog post)
View MemoFib.hs
-- 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
You can’t perform that action at this time.