Skip to content

Instantly share code, notes, and snippets.

@oyms
Created August 17, 2012 15:13
Show Gist options
  • Save oyms/3379727 to your computer and use it in GitHub Desktop.
Save oyms/3379727 to your computer and use it in GitHub Desktop.
Division without operators
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