Created
May 13, 2015 10:13
-
-
Save sheepcloud/1de3e58bab2c0c079ddd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
static void Main(string[] args) | |
{ | |
var sources = "123456789"; | |
var comm = " +-"; | |
var insertPoint = sources.Length - 1; | |
var commCount = comm.Length; | |
const int value = 100; | |
System.Data.DataTable dt = new System.Data.DataTable(); | |
foreach (var v in Enumerable.Range(0, (int)Math.Pow(commCount, insertPoint))) | |
{ | |
var formula = sources; | |
foreach (var n in Enumerable.Range(0, insertPoint).Reverse()) | |
{ | |
var index = (v / (int)Math.Pow(commCount, n)) % commCount; | |
formula = (index == 0) ? formula : formula.Insert(n + 1, new string(new[] { comm.ElementAt(index) })); | |
} | |
var result = (int)dt.Compute(formula, ""); | |
if (result == value) | |
Console.WriteLine(formula + " = " + result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment