Skip to content

Instantly share code, notes, and snippets.

@compustar
Last active March 27, 2016 05:44
Show Gist options
  • Select an option

  • Save compustar/caf260582f7bf67f46be to your computer and use it in GitHub Desktop.

Select an option

Save compustar/caf260582f7bf67f46be to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
public class Program {
public static void Main() {
for (int i = 10; i < 100; i++) {
if (CountDigits(i, 111 - i) == 4) {
for (int j = 10; j < 100; j++) {
if (CountDigits(j, i + j, i, 111 - i) == 8 && i + j > 9 && i + j < 100) {
Console.WriteLine(string.Format("{2} - {3} = {0} + {1} = 111", i, 111 - i, j, i + j));
}
}
}
}
}
public static int CountDigits(params int[] numbers) {
return numbers.SelectMany(o => new int[]{o / 10, o % 10}).Distinct().Count();
/*
var x = new HashSet<int>();
foreach (var n in numbers) {
x.Add(n / 10);
x.Add(n % 10);
}
return x.Count;
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment