fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var nums = new List<string>();
  10. for (var i = 0L; i <= 99999L; i += 101)
  11. {
  12. var s = i.ToString().PadLeft(9, '0');
  13. if (!nums.Any(n => LessThan2SequentialCharsDiff(n, s)))
  14. nums.Add(s);
  15. else
  16. Console.WriteLine("Not valid: " + s);
  17. if (i % 10000L < 101) Console.WriteLine(i);
  18. }
  19. Console.WriteLine("Count: " + nums.Count);
  20. }
  21.  
  22. public static bool LessThan2SequentialCharsDiff(string a, string b)
  23. {
  24. var diffCount = 0;
  25. var timesCount = 0;
  26. var isSequential = false;
  27. for (var i = 0; i < a.Length && diffCount <= 2 && timesCount <= 1; i++)
  28. if (a[i] != b[i])
  29. {
  30. if (!isSequential) timesCount++;
  31. diffCount++;
  32. isSequential = true;
  33. }
  34. else
  35. {
  36. diffCount = 0;
  37. isSequential = false;
  38. }
  39. return diffCount <= 2 && timesCount <= 1;
  40. }
  41. }
Success #stdin #stdout 0.14s 34088KB
stdin
Standard input is empty
stdout
0
10100
20099
30098
40097
50096
60095
70094
80093
90092
Count: 991