Skip to content

Instantly share code, notes, and snippets.

@chapeti
Last active September 28, 2015 03:07
Show Gist options
  • Save chapeti/bb8411175892d8b976d9 to your computer and use it in GitHub Desktop.
Save chapeti/bb8411175892d8b976d9 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace HexactaChallenge
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("9, 22, 1, 3 = " + Min(new[] { 9, 22, 1, 3 }));
Console.WriteLine("10, 1, 1, 1, 1, 14 = " + Min(new[] { 10, 1, 1, 1, 1, 14 }));
Console.WriteLine("2, 20, 21, 23 = " + Min(new[] { 2, 20, 21, 23 }));
Console.WriteLine("91, 22, 1, 3 = " + Min(new[] { 91, 22, 1, 3 }));
Console.WriteLine("112, 113 = " + Min(new[] { 112, 113 }));
Console.WriteLine("21, 3 = " + Min(new[] { 21, 3 }));
WaitForEscapeKey();
}
public static long Min(int[] numbers)
{
var orderedList = numbers.ToList();
orderedList.Sort((x, y) =>
{
var a = int.Parse(string.Format("{0}{1}", x, y));
var b = int.Parse(string.Format("{0}{1}", y, x));
return a > b ? 1 : -1;
});
return long.Parse(orderedList.Aggregate("", (c, n) => c + n));
}
private static void WaitForEscapeKey()
{
do { while (!Console.KeyAvailable) {} } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment