Skip to content

Instantly share code, notes, and snippets.

View manudatta's full-sized avatar

Manu Datta manudatta

  • Singapore
View GitHub Profile
@manudatta
manudatta / main.py
Last active January 16, 2021 07:59
parsing and printing guarantees
#!/usr/bin/env python3
import csv
import sys
from collections import namedtuple
from datetime import datetime
Guarantee = namedtuple("Guarantee", "end_date address")
DEFAULT_CALCULATION_DATE = datetime(2020, 5, 2)
DEFULAT_FILE_NAME = "./guarantees_end.csv"
# Author: manu.datta@gmail.com
# balanced partition problem
def solution(A):
a = list(map(abs,A)) # specific to codility problem
L = len(a)
if L == 1:
return a[0]
array_sum = sum(a)
half,m = divmod(array_sum,2)
#print(half,m)
@manudatta
manudatta / zero_one_knapsack.py
Created January 11, 2020 14:24
0-1 knapsack implementation in python
# Author: manu.datta@gmail.com
# zero-one knapsack implementation in python
items = {
'a': (12,4)
,'b':(10,6)
,'c':(8,5)
,'d':(11,7)
,'e':(14,3)
"""
CDMA: encoding decoding in python
Author: manu.datta@gmail.com
"""
import itertools
import operator
def mux(codes,data):
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
@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
@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 / 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 / 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 / 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))))