Skip to content

Instantly share code, notes, and snippets.

@wayne-o
Created September 18, 2015 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayne-o/d18c28750439a3168bad to your computer and use it in GitHub Desktop.
Save wayne-o/d18c28750439a3168bad to your computer and use it in GitHub Desktop.
Multuplier - long winded
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