Created
November 3, 2012 19:19
-
-
Save WouterG/4008344 to your computer and use it in GitHub Desktop.
Puzzle solver triangle ( A = diff of b&c )
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; | |
class Program | |
{ | |
private static int a = 5, | |
b = 9, | |
c = 4, | |
d = 1, | |
e = 1, | |
f = 1, | |
g = 1, | |
h = 1, | |
i = 1, | |
j = 1, | |
k = 1, | |
l = 1, | |
m = 1, | |
n = 1, | |
o = 1; | |
private static void Main(string[] args) | |
{ | |
string s1 = " {0}"; | |
string s2 = " {0} {1}"; | |
string s3 = " {0} {1} {2}"; | |
string s4 = " {0} {1} {2} {3}"; | |
string s5 = "{0} {1} {2} {3} {4}"; | |
for (; d < 16; d++) | |
for (; e < 16; e++) | |
for (; f < 16; f++) | |
for (; g < 16; g++) | |
for (; h < 16; h++) | |
for (; i < 16; i++) | |
for (; j < 16; j++) | |
for (; k < 16; k++) | |
for (; l < 16; l++) | |
for (; m < 16; m++) | |
for (; n < 16; n++) | |
for (; o < 16; o++) | |
if (Check()) | |
{ | |
Console.WriteLine("Found it!"); | |
Console.WriteLine(s1, a); | |
Console.WriteLine(s2, b, c); | |
Console.WriteLine(s3, d, e, f); | |
Console.WriteLine(s4, g, h, i, j); | |
Console.WriteLine(s5, k, l, m, n, o); | |
Console.ReadKey(true); | |
return; | |
} | |
Console.WriteLine("No answer!"); | |
Console.ReadKey(true); | |
} | |
private static bool Check() | |
{ | |
if (Math.Abs(d - e) != b) return false; | |
if (Math.Abs(e - f) != c) return false; | |
if (Math.Abs(g - h) != d) return false; | |
if (Math.Abs(h - i) != e) return false; | |
if (Math.Abs(i - j) != f) return false; | |
if (Math.Abs(k - l) != g) return false; | |
if (Math.Abs(l - m) != h) return false; | |
if (Math.Abs(m - n) != i) return false; | |
if (Math.Abs(n - o) != j) return false; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment