Last active
August 29, 2015 14:04
-
-
Save boyanov83/f2c099a02000d0fa6653 to your computer and use it in GitHub Desktop.
Nine Digit Magic Numbers
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 NineDigitMagicNumbers | |
{ | |
static void Main() | |
{ | |
int sum = int.Parse(Console.ReadLine()); | |
int diff = int.Parse(Console.ReadLine()); | |
int abc = 0; | |
int def = 0; | |
int ghi = 0; | |
bool check = false; | |
for (int a = 1; a < 8; a++) | |
{ | |
for (int b = 1; b < 8; b++) | |
{ | |
for (int c = 1; c < 8; c++) | |
{ | |
for (int d = 1; d < 8; d++) | |
{ | |
for (int e = 1; e < 8; e++) | |
{ | |
for (int f = 1; f < 8; f++) | |
{ | |
for (int g = 1; g < 8; g++) | |
{ | |
for (int h = 1; h < 8; h++) | |
{ | |
for (int i = 1; i < 8; i++) | |
{ | |
abc = a * 100 + b * 10 + c; | |
def = d * 100 + e * 10 + f; | |
ghi = g * 100 + h * 10 + i; | |
if (a+b+c+d+e+f+g+h+i == sum && ghi-def == diff && def-abc == diff && ghi >= def && def >= abc) | |
{ | |
Console.WriteLine(abc + "" + def + "" + ghi); | |
check = true; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
if (check == false) | |
{ | |
Console.WriteLine("No"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment