Created
September 18, 2015 07:08
-
-
Save wayne-o/d18c28750439a3168bad to your computer and use it in GitHub Desktop.
Multuplier - long winded
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
using System; | |
using System.Collections.Generic; | |
public static class Extensions{ | |
public static IEnumerable<int> To(this int from, int to) | |
{ | |
for (int i = from; i <= to; i++) | |
{ | |
yield return i; | |
} | |
} | |
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) | |
{ | |
foreach (T item in items) | |
{ | |
action(item); | |
} | |
} | |
} | |
public static class Program | |
{ | |
public static uint MultiplyNumbers(uint x, uint y) | |
{ | |
uint result = 0; | |
var baseMultiplier = x < y ? y : x; | |
var times = x < y ? x : y; | |
0.To((int)baseMultiplier-1).ForEach(idx => result += times); | |
return (uint)result; | |
} | |
public static void Main(string[] args) | |
{ | |
var result = MultiplyNumbers(3,2); | |
Console.WriteLine(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment