fork(1) download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var arr = new[,] { { 3, 3, 3, 2, 1 },
  9. { 2, 4, 3, 3, 3 },
  10. { 3, 3, 4, 3, 1 },
  11. { 2, 3, 5, 3, 1 } };
  12. int width = arr.GetLength(0), height = arr.GetLength(1), length = 3, value = 3;
  13. var h = Enumerable.Range(0, width)
  14. .SelectMany(x => Enumerable.Range(0, height - length + 1)
  15. .Select(y => Enumerable.Range(0, length)
  16. .Select(o => new { x, y = y + o }))
  17. .Where(c => c.All(p => arr[p.x, p.y] == value))
  18. .SelectMany(c => c));
  19. var v = Enumerable.Range(0, width - length + 1)
  20. .SelectMany(x => Enumerable.Range(0, height)
  21. .Select(y => Enumerable.Range(0, length)
  22. .Select(o => new { x = x + o, y }))
  23. .Where(c => c.All(p => arr[p.x, p.y] == value))
  24. .SelectMany(c => c));
  25. var all = h.Concat(v).Distinct();
  26. Console.WriteLine(string.Join("\n", all));
  27. }
  28. }
Success #stdin #stdout 0.02s 132544KB
stdin
Standard input is empty
stdout
{ x = 0, y = 0 }
{ x = 0, y = 1 }
{ x = 0, y = 2 }
{ x = 1, y = 2 }
{ x = 1, y = 3 }
{ x = 1, y = 4 }
{ x = 2, y = 3 }
{ x = 3, y = 3 }