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 GetPrimeByIndex(int index){ | |
//Terrible, Horrible, No Good, Very Inneficient implementation | |
List<int> primes = new List<int>{2}; | |
int value = 3; | |
while (primes.Count != index){ | |
bool isPrime = true; | |
for (int i=3; i<value; i+=2){ | |
if (value % i == 0){ | |
isPrime = false; |
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
long GetMaxCutout(long number, int skipDigits){ | |
for (int i = 0; i<skipDigits; i++){ | |
number = SkipOneDigit(number); | |
} | |
return number; | |
} | |
long SkipOneDigit(long number){ | |
var max = long.MinValue; | |
var strNumber = number.ToString(); |
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() | |
{ | |
var chances = Enumerable.Range(0, 10000000).Select(i => new Chance{Value = i}).ToList(); | |
Stopwatch c = Stopwatch.StartNew(); | |
var fresult = CountChances(chances); | |
c.Stop(); | |
//c.Dump(); | |
c = Stopwatch.StartNew(); |
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() | |
{ | |
int[] numbers = {1,2,3,4,5,6,7,8,9}; | |
var combinations = GetCombinations(8, 3); | |
foreach(var comb in combinations) | |
{ | |
StringBuilder display = new StringBuilder("1"); | |
var running = 0; | |
var current = 1; | |
var op = 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
public static class EnumerableHierarchyExtensions | |
{ | |
/// <summary> | |
/// A wrapper for an item that includes the level the item has in the hierarchy | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
public class Leveled<T> | |
{ | |
/// <summary> | |
/// The wrapped item |
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() | |
{ | |
//no comparisons are used, only dictionary lookup | |
// the key Tuple<bool, bool> determines if the value is divisible by 3 (first bool) and by 5 (second bool) | |
//the value is a function taking an integer and returning a string | |
Dictionary<Tuple<bool, bool>, Func<int, string>> dict= new Dictionary<Tuple<bool, bool>, Func<int, string>>(); | |
//if the number is not divisible by anything, return the value of the number | |
dict.Add(Tuple.Create(false, false), i => i.ToString()); |
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
/// <summary> | |
/// Given two collections, determines added, removed and changed items. | |
/// </summary> | |
public class ListDifference<T> | |
{ | |
/// <summary> | |
/// The items that were added to the collection | |
/// </summary> | |
public IEnumerable<T> AddedItems { get; private set; } |
NewerOlder