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
//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() | |
{ | |
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
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
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) |
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
#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; |
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() | |
{ | |
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; | |
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
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>(); |
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
//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 |
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
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)) |