Skip to content

Instantly share code, notes, and snippets.

View manudatta's full-sized avatar

Manu Datta manudatta

  • Singapore
View GitHub Profile
@manudatta
manudatta / topologicalsort.mips.s
Created December 14, 2012 06:08
Topological sort in MIPS assembly language. Tested in SPIM simulator.
# Copyright 2002 Manu Datta
# All rights reserved
.data
adjMatrix: .space 450
.align 2
count: .space 225
#msg1: .asciiz "Error in toplogical sort:\n"
#msg2: .asciiz "graph contanis a cycle\n"
msg3: .asciiz "Vertex : "
@manudatta
manudatta / bubblesort.mips.s
Created December 14, 2012 08:34
Bubble sort in MIPS assembly.
# Copyright 2002 Manu Datta (gmail.com ID Manu dot Datta)
# All rights reserved
.data
msg1: .asciiz "\nEnter integer values followed by return (-1 terminates input): \n"
msg2: .asciiz ","
msg3: .asciiz "Bubble Sort"
msg4: .asciiz "#########pass#########"
msg5: .asciiz "\n"
msg6: .asciiz "\nNumber list has been sorted\n"
;pg 102. Ex 3.22.c
(defn myfun [x y] (list (list x) y))
(myfun 'alpha 'beta)
;.d
(defn firstp? [ e collection] (= e (first collection)))--clojure uses ? instead of p for predicate (lisp convention)
(firstp? 'foo '(foo bar baz))
(firstp? 'boing '(foo bar baz)) -- clojure has false instead of nil
;.e
(defn mid-add1 [sentence] (list (first sentence) (+ 1 (second sentence)) (last sentence)))
(mid-add1 '(take 2 cookies))
@manudatta
manudatta / chap5keyboard.clj
Created January 26, 2013 21:27
Chapter 5 keyboard exercise Craps game in clojure
;pg 151
(defn throw-die [] (+ 1 (rand-int 6)))
(defn throw-dice [] (list (throw-die) (throw-die)))
(throw-dice)
(defn snake-eyes? [dice-throw] (= '(1 1) dice-throw))
(snake-eyes? '(3 1))
(defn boxcar? [dice-throw] (= '(6 6) dice-throw))
(boxcar? '(6 6))
; intro of let
(defn instant-win? [dice-throw] (let [dice-throw-sum (reduce + dice-throw)] (or (= 7 dice-throw-sum) (= 11 dice-throw-sum))))
@manudatta
manudatta / p99.erl
Last active December 15, 2015 13:49
P99 problems in Erlang
% Author: Manu Dot Datta At Gmail dot com
-module(p99).
-compile(export_all).% 1.26
%1.26
% Generate the combinations of K distinct objects chosen from the N elements of a list
% usage: p99:combination(N,List) N < length(L) is length of combinations
% example:
%p99:combination(3,[a,b,c]). => [[a,b,c],[a,c,b],[b,a,c],[b,c,a],[c,a,b],[c,b,a]]
@manudatta
manudatta / fib.s
Created April 3, 2013 21:57
Fibonacci series in MIPS,SPIM
-- Copy right (c) Manu dot Datta @ gmail dot com
.data
msg1: .asciiz "Enter a positive index for Fibonacci Calculation : "
msg2: .asciiz "The Finonacci number is : "
msg3: .asciiz "Recusive calls made to Fibonacci : "
msgerr1: .asciiz "The Finonacci number is : 1 \n"
msgerr2: .asciiz "Recusive calls made to Fibonacci : 0 \n"
nl: .asciiz "\n";
@manudatta
manudatta / googlerank.py
Created October 12, 2013 10:36
Wrote this program in 2003 to find google rank of a site given search items. Use it on your own risk.
#! path to python
# copyright manu.datta gmail.com
import string
import getopt
import sys
import ConfigParser
import re
UsageErr ='googlerank -n <number> -d <website> -c <domain> <Search Word>'
@manudatta
manudatta / pystreams.py
Created August 14, 2014 04:56
Python streams implementation sample
def ones():
return 1,lambda : ones()
def power_of_two(x=1):
return x,lambda : power_of_two(x*2)
def fibonacci(xcurr=1,xlast=0):
xnext = xcurr+xlast
return xnext,lambda : fibonacci(xnext,xcurr)
def list_iter(l=[]):
if len(l) == 0 :
raise StopIteration
import copy
import sys
def greater_path(path1,path2):
(path_list1,elevation1,last_heightl1) = path1
(path_list2,elevation2,last_heightl2) = path2
len1 = len(path_list1)
len2 = len(path_list2)
if len1 != len2:
return len1 > len2
return elevation1 > elevation2
"""
CDMA: encoding decoding in python
Author: manu.datta@gmail.com
"""
import itertools
import operator
def mux(codes,data):