Skip to content

Instantly share code, notes, and snippets.

@robbestad
Created December 20, 2016 10:32
Show Gist options
  • Save robbestad/ec7ae48baceab828e90c2758abee1132 to your computer and use it in GitHub Desktop.
Save robbestad/ec7ae48baceab828e90c2758abee1132 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var bestProduct = 0L;
for (var i = 0; i < 0x1 << 10; i++)
{
var left = long.Parse("0" + string.Join("", Enumerable.Range(0, 10).Where(x => (i & (0x1 << x)) > 0).OrderByDescending(x => x)));
var right = long.Parse("0" + string.Join("", Enumerable.Range(0, 10).Where(x => (i & (0x1 << x)) == 0).OrderByDescending(x => x)));
if (left*right > bestProduct)
{
bestProduct = left*right;
}
}
Console.WriteLine(bestProduct);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment