Created
October 13, 2012 12:39
-
-
Save kazuk/3884518 to your computer and use it in GitHub Desktop.
SEND+MORE=MONEY
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; | |
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) | |
from y in Enumerable.Range(1, 9).Where(x => x != s && x != e && x != n && x != d && x != m && x != o && x!=r ) | |
let send = s * 1000 + e * 100 + n * 10 + d | |
let more = m * 1000 + o * 100 + r * 10 + e | |
let money = m * 10000 + o *1000 + n * 100 + e * 10 + y | |
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment