Created
March 1, 2014 00:02
-
-
Save Vannevelj/9282531 to your computer and use it in GitHub Desktop.
Hot streak pattern finder - http://stackoverflow.com/questions/22107092/how-to-detect-a-hot-streak-in-a-pattern-of-numbers
This file contains 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() | |
{ | |
for(int i = 0; i < 5; i++){ | |
var list = GetList(); | |
DisplayList(list); | |
GetHotStreaks(list); | |
} | |
} | |
private static Random rand = new Random(); | |
private List<int> GetList(){ | |
var list = new List<int>(); | |
for(int i = 0; i < 50; i++){ | |
list.Add(rand.Next(1, 40)); | |
} | |
return list; | |
} | |
private void DisplayList(List<int> list){ | |
for(int i = 0; i < list.Count; i++){ | |
Console.Write(list[i] + " "); | |
} | |
Console.WriteLine(); | |
} | |
private void GetHotStreaks(List<int> list){ | |
double treshold = 0.95; | |
bool found = false; | |
while(treshold > 0.0){ | |
for(int i = 0; i < list.Count - 2; i++){ | |
if(AreWithinRange(list[i], list[i + 1], list[i + 2], treshold)){ | |
Console.WriteLine (string.Format("Possible hot streak (treshold {0}): {1} - {2} - {3}", treshold, list[i], list[i + 1], list[i + 2])); | |
found = true; | |
} | |
} | |
if(found){ | |
Console.WriteLine (); | |
return; | |
} | |
treshold -= 0.05; | |
} | |
} | |
private bool AreWithinRange(int val1, int val2, int val3, double treshold){ | |
return AreWithinRange(val1, val2, treshold) && AreWithinRange(val2, val3, treshold); | |
} | |
// http://www.oracle.com/webfolder/technetwork/data-quality/edqhelp/Content/processor_library/matching/comparisons/percent_difference.htm | |
private bool AreWithinRange(int val1, int val2, double treshold){ | |
double max = Math.Max(val1, val2); | |
double min = Math.Min(val1, val2); | |
double pd = (max - min) / min; | |
//Console.WriteLine ("Values: val1: {0}\t val2: {1}\t PD: {2}\t T: {3}", val1, val2, pd, treshold); | |
return pd <= 1 - treshold; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment