Skip to content

Instantly share code, notes, and snippets.

@kazuk
Created October 13, 2012 12:28
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 kazuk/3884462 to your computer and use it in GitHub Desktop.
Save kazuk/3884462 to your computer and use it in GitHub Desktop.
SEND+MORE=MONEY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SendMoreMoney
{
class Program
{
static void Main(string[] args)
{
var q = from s in Enumerable.Range(1, 9)
from e in Enumerable.Range(1, 9).Where(x => x != s)
from n in Enumerable.Range(1, 9).Where(x => x != s && x != e)
from d in Enumerable.Range(1, 9).Where(x => x != s && x != e && x != n)
from m in Enumerable.Range(1, 9).Where(x => x != s && x != e && x != n && x != d)
from o in Enumerable.Range(1, 9).Where(x => x != s && x != e && x != n && x != d && x != m)
from r in Enumerable.Range(1, 9).Where(x => x != s && x != e && x != n && x != d && x != m && x != o)
let send = s * 1000 + e * 100 + n * 10 + d
let more = m * 1000 + o * 100 + r * 10 + e
let money = send + more
where send + more == money
select new { send, more, money };
var sw = System.Diagnostics.Stopwatch.StartNew();
var results = q.ToList();
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.ReadLine();
foreach (var result in results)
{
Console.WriteLine(result);
}
}
}
}
@kazuk
Copy link
Author

kazuk commented Oct 13, 2012

@kazuk
Copy link
Author

kazuk commented Oct 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment