Skip to content

Instantly share code, notes, and snippets.

View sudipto80's full-sized avatar
🎯
Focusing

SUDIPTA MUKHERJEE sudipto80

🎯
Focusing
View GitHub Profile
@sudipto80
sudipto80 / CartesianProduct.cs
Last active January 4, 2016 09:06
CartesianProduct
void Main()
{
Cartesian<int>(new List<List<int>>()
{new List<int>(){1,2,3},
new List<int>(){3,2},
new List<int>(){5,6,7}}).Dump();
Cartesian<string>(new List<List<string>>()
{ new List<string>() { "A", "B" },
new List<string>() { "C", "D", "E" }}).Dump();
@sudipto80
sudipto80 / Doublet.cs
Last active January 4, 2016 09:24
Doublet Cheater
void Main()
{
HashSet<string> allWords = new HashSet<string>(File.ReadAllText(@"C:\T9.txt")
.Split(new char[]{' ','\n'},StringSplitOptions.RemoveEmptyEntries));
Transform2("myth","fact",allWords).Dump("Transform2");
Transform2("damp","like",allWords).Dump("Transform2");
Transform2("door","room",allWords).Dump("Transform2");
Transform2("dawn","boat",allWords).Dump("Transform2");
Transform2("dear","read",allWords).Dump("Transform2");
@sudipto80
sudipto80 / AlgoP.cs
Created January 4, 2016 09:11
Algorithm P
//Algorithm P
int[] nums = { 1, 3, 54, 67, 123, 234, 3546, 21, 3, 45 };
for (int i = 0; i < nums.Length; i++)
{
int x = new Random().Next(i, nums.Length - 1);
int y = nums[x];
nums[x] = nums[i];
nums[i] = y;
}
@sudipto80
sudipto80 / LongestConsecutive.cs
Created January 7, 2016 10:46
Longest Consecutive Sequence
int[] nums = {1,6,10,4,7,9,12,11,5,13};
int max = nums.Max ( );
int[] vals = new int[max+1];
for(int i = 0;i<nums.Length;i++)
vals[nums[i]]++;
Dictionary<int,int> lengthMap = new Dictionary<int,int>();
int k=0;
for(k=1;k<vals.Length;k++)
@sudipto80
sudipto80 / Infix.cs
Created January 7, 2016 10:53
Infix Evaluation using Stack
string ops = "+-*/";
string vals = "1234567890";
Stack<char> opStack = new Stack<char>();
Stack<int> valStack = new Stack<int>();
void Main()
{
string expr = "(1 + ((2+3)*(4*5)))";
foreach (char c in expr)
@sudipto80
sudipto80 / JollyJumper.c
Created January 13, 2016 11:23
Jolly Jumper
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int jolly( int nums[], int length)
{
//Pre-conditions
if(length <= 0 )
return 0;
int i;
@sudipto80
sudipto80 / BinarySearch.cs
Created January 19, 2016 12:34
Binary Search
void Main()
{
BinarySearch(new int[]{1,3,4,5,9,10},1).Dump();
}
int BinarySearch(int[] array,int x)
{
int low = 0;
int high = array.Length - 1;
@sudipto80
sudipto80 / BFS.cs
Created January 19, 2016 12:35
BFS
Dictionary<string,List<string>> graph =
new Dictionary<string,List<string>>();
graph.Add("A",new List<string>(){"B","C","D"});
graph.Add("B",new List<string>(){"A","E","F"});
graph.Add("E",new List<string>(){"B","G"});
List<string> visited = new List<string>();
Queue<string> qu = new Queue<string>();
@sudipto80
sudipto80 / rmse.fs
Created January 20, 2016 05:41
Root mean squared error
//root mean squared error
let rmse(ratings:float list)(predictions:float list) =
sqrt(( List.zip ratings predictions |> List.map (fun t -> fst t - snd t) |> List.sum )
/(float predictions.Length ))
rmse [1.3;4.5] [4.1;0.41] |> Dump
@sudipto80
sudipto80 / Pearsons.fs
Created January 21, 2016 01:40
Pearsons Coefficient
let x = [1.;2.;3.;4.;5.]
let y = [1.;2.;2.;3.;4.]
let z = [3;4]
let x_bar = List.average x
let y_bar = List.average y
let numerator =
List.zip x y
|> List.sumBy (fun item -> (fst item - x_bar)*(snd item - y_bar))