Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- class a
- {
- public List<int[][]> combinations(int[][] array1, int count1, int[][] array2, int count2)
- {
- List<int[][]> result= new List<int[][]>();
- combine(array1, count1, array2, count2, new int[4][], out result);
- return result;
- }
- public void combine(int[][] array1, int count1, int[][] array2, int count2, int[][] chosen, out List<int[][]> result)
- {
- int[][] temp;
- if (count1>0) {
- count1--;
- for (int i = 0; i < array1.GetLength(0) - count1; i++) {
- temp = Concat(chosen,array1); // this copies the array
- combine(array1.WHAT?, count1, array2, count2, temp, result);
- }
- } else if (count2>0) {
- //count2--;
- //for (i = 0; i < array2.length - count2; i++) {
- // temp = chosen.concat([array2[i]]);
- // combine(null, 0, array2.slice(i + 1), count2, temp, result);
- } else {
- result.Add(chosen); // don't need to copy here, just accumulate results
- }
- }
- public static T[] Concat<T>(this T[] x, T[] y)
- {
- if (x == null) throw new ArgumentNullException("x");
- if (y == null) throw new ArgumentNullException("y");
- int oldLen = x.Length;
- Array.Resize<T>(ref x, x.Length + y.Length);
- Array.Copy(y, 0, x, oldLen, y.Length);
- return x;
- }
- public static IEnumerable<T> SliceRow<T>(this T[,] array, int row)
- {
- for (var i = 0; i < array.GetLength(0); i++)
- {
- yield return array[i, row];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement