fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. private static void DoIt(IEnumerable<int> a)
  8. {
  9. Console.WriteLine(String.Join(" ", a));
  10.  
  11. foreach (var x in a.Zip(a.Skip(1), (x, y) => Enumerable.Repeat(x, 1).Concat(Enumerable.Repeat(y, 1))).Zip(a.Skip(2), (xy, z) => xy.Concat(Enumerable.Repeat(z, 1))).Where((x, i) => i % 3 == 0))
  12. Console.WriteLine(String.Join(" ", x));
  13.  
  14. Console.WriteLine();
  15. }
  16.  
  17. public static void Main()
  18. {
  19. DoIt(new int[] {1});
  20. DoIt(new int[] {1, 2});
  21. DoIt(new int[] {1, 2, 3});
  22. DoIt(new int[] {1, 2, 3, 4});
  23. DoIt(new int[] {1, 2, 3, 4, 5});
  24. DoIt(new int[] {1, 2, 3, 4, 5, 6});
  25. }
  26. }
Success #stdin #stdout 0.02s 16180KB
stdin
Standard input is empty
stdout
1

1 2

1 2 3
1 2 3

1 2 3 4
1 2 3

1 2 3 4 5
1 2 3

1 2 3 4 5 6
1 2 3
4 5 6