internal TmpPartition add(int a) { TmpPartition result = new TmpPartition(); result.remainder = remainder - a; result.partition = new List <int>(); result.partition.AddRange(partition); result.partition.Add(a); return(result); }
private static void Partition(TmpPartition x, ICollection <int[]> allPartitions, int len) { if (x.remainder == 0 && x.partition.Count == len) { allPartitions.Add(x.partition.ToArray()); return; } if (x.partition.Count == len) { return; } for (int i = 0; i <= x.remainder; i++) { Partition(x.add(i), allPartitions, len); } }
internal TmpPartition Add(int a) { TmpPartition result = new TmpPartition{remainder = remainder - a, partition = new List<int>()}; result.partition.AddRange(partition); result.partition.Add(a); return result; }
private static void Partition(TmpPartition x, ICollection<int[]> allPartitions, int len, Func<int[], bool> validPartition, Action<int[]> task) { if (x.remainder == 0 && x.partition.Count == len){ int[] part = x.partition.ToArray(); if (validPartition == null || validPartition(part)){ if (task != null){ task(part); } else{ allPartitions.Add(part); } } return; } if (x.partition.Count == len){ return; } for (int i = 0; i <= x.remainder; i++){ Partition(x.Add(i), allPartitions, len, validPartition, task); } }