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 / 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 / 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 / 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 / FizzBuzzBySetTheory.cs
Created December 14, 2015 03:51
FizzBuzz using Set Theory
var range = Enumerable.Range(1,40);
var mod3 = range.Where(e => e % 3 == 0);
var mod5 = range.Where(e => e % 5 == 0);
var mod15 = mod3.Intersect(mod5);
//Find numbers that are divisible by 3 but not by 5 or 15
mod3 = mod3.Except(mod15);
//Find numbers that are divisible by 5 but not by 3 or 15
mod5 = mod5.Except(mod15);
//Find integers that are not divisible by either 3 or 5
@sudipto80
sudipto80 / ExtendedEventBeautifier.cs
Last active November 27, 2015 09:17
Making Extended Events Creation SQL Beautiful
void Main()
{
string tsql = @"CREATE EVENT SESSION [CheckMyQuery] ON SERVER
ADD EVENT sqlserver.lock_acquired(SET collect_database_name=(1),collect_resource_description=(1)
ACTION(package0.collect_cpu_cycle_time,sqlos.task_time,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_id,sqlserver.database_name,sqlserver.nt_username,sqlserver.plan_handle,sqlserver.query_hash,sqlserver.server_instance_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.sql_text,sqlserver.username)
WHERE ([sqlserver].[equal_i_sql_unicode_string]([database_name],N'MyDB'))),
ADD EVENT sqlserver.lock_released(
ACTION(sqlos.task_time,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_name,sqlserver.nt_username,sqlserver.query_hash,sqlserver.server_instance_name,sqlserver.session_nt_username,sqlserver.sql_text,sqlserver.username)
WHERE ([sqlserver].[database_name]='MyDB')),
ADD EVENT sqlserver.lock_timeout(
@sudipto80
sudipto80 / lettercombo.cs
Created September 18, 2015 02:52
Generate all case for all letters in a word using LINQ
void Main()
{
string word = "abcd";
List<List<string>> letters = new List<List<string>>();
letters = word.ToCharArray().Select(w => new List<string>(){w.ToString().ToLower(),w.ToString().ToUpper()} ).ToList();
CartesianProduct(letters)
.Select (x => x.Aggregate ((a,b) => a + b))
@sudipto80
sudipto80 / bookOrg.cs
Created September 15, 2015 19:44
Squirrel to organize books
Table books = DataAcquisition.LoadCSV(@"C:\personal\books.csv");
//genre,author,height-genre*author
books.AddColumn("GenreAsNum", books.ValuesOf("Genre"));
books.Transform("GenreAsNum", x => x == "fiction" ? "1" : x == "nonfiction" ?
"2" : x == "philosophy" ?
"3" : x == "science" ?
"4" : x == "tech" ?
"5" :
"-1");
books = books.Transform("Author", x =>
@sudipto80
sudipto80 / gist:5924e76c6570d2d7547c
Created September 15, 2015 19:33
Books per bookshelf
Moon is Down, The Steinbeck fiction 196
Winter of Our Discontent, The Steinbeck fiction 196
Grapes of Wrath, The Steinbeck fiction 196
Great Indian Novel, The Tharoor fiction 198
20000 Leagues Under the Sea Verne fiction 190
Slaughterhouse Five Vonnegut fiction 198
----------
Title Author Genre Height
Final Crisis fiction 257
Crisis on Infinite Earths fiction 258
@sudipto80
sudipto80 / gist:84e5280c4eb1bda427b4
Last active September 15, 2015 19:29
Arranging books in your bookshelves
Table books = DataAcquisition.LoadCSV(@"C:\personal\books.csv");
//genre,author,height-genre*author
books.AddColumn("GenreAsNum", books.ValuesOf("Genre"));
books.Transform("GenreAsNum", x => x == "fiction" ? "1" : x == "nonfiction" ?
"2" : x == "philosophy" ?
"3" : x == "science" ?
"4" : x == "tech" ?
"5" :
"-1");
books = books.Transform("Author", x =>