This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => |