Created
August 17, 2012 15:13
-
-
Save oyms/3379727 to your computer and use it in GitHub Desktop.
Division without operators
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
public static int Division(int divident, int divisor) | |
{ | |
if (divisor == 0) throw new DivideByZeroException("Jeg tror aldri tidligere jeg har kunnet bruke denne"); | |
var enumerator = Enumerable.Range(1, divident).GetEnumerator(); | |
var lists = new List<int>[divisor]; | |
do | |
{ | |
foreach (var element in Enumerable.Range(0, divisor)) | |
{ | |
var list = lists[element] ?? (lists[element] = new List<int>()); | |
if (!enumerator.MoveNext()) return lists.Last().Count(); | |
list.Add(enumerator.Current); | |
} | |
} while (true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment