Advertisement
Guest User

Untitled

a guest
Nov 24th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class a
  7. {
  8. public List<int[][]> combinations(int[][] array1, int count1, int[][] array2, int count2)
  9. {
  10. List<int[][]> result= new List<int[][]>();
  11. combine(array1, count1, array2, count2, new int[4][], out result);
  12. return result;
  13. }
  14.  
  15. public void combine(int[][] array1, int count1, int[][] array2, int count2, int[][] chosen, out List<int[][]> result)
  16. {
  17.  
  18. int[][] temp;
  19.  
  20. if (count1>0) {
  21. count1--;
  22. for (int i = 0; i < array1.GetLength(0) - count1; i++) {
  23. temp = Concat(chosen,array1); // this copies the array
  24. combine(array1.WHAT?, count1, array2, count2, temp, result);
  25. }
  26. } else if (count2>0) {
  27. //count2--;
  28. //for (i = 0; i < array2.length - count2; i++) {
  29. // temp = chosen.concat([array2[i]]);
  30. // combine(null, 0, array2.slice(i + 1), count2, temp, result);
  31.  
  32. } else {
  33. result.Add(chosen); // don't need to copy here, just accumulate results
  34. }
  35. }
  36. public static T[] Concat<T>(this T[] x, T[] y)
  37. {
  38. if (x == null) throw new ArgumentNullException("x");
  39. if (y == null) throw new ArgumentNullException("y");
  40. int oldLen = x.Length;
  41. Array.Resize<T>(ref x, x.Length + y.Length);
  42. Array.Copy(y, 0, x, oldLen, y.Length);
  43. return x;
  44. }
  45.  
  46. public static IEnumerable<T> SliceRow<T>(this T[,] array, int row)
  47. {
  48. for (var i = 0; i < array.GetLength(0); i++)
  49. {
  50. yield return array[i, row];
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement