-4

Function receives char[,].

For example if it it takes

000
LAD
0B0

Traversing should print out all possible combinations of non-zero chars:

L
LA
LAD
LAB
A
AL
AB
AD

and so on

private void Traverse(char[,] area) 
{

}
EngineerSpock
  • 2,575
  • 4
  • 35
  • 57
  • Please post your code. – Vimal Stan May 03 '13 at 17:46
  • This example may be helpful: http://stackoverflow.com/questions/756055/listing-all-permutations-of-a-string-integer – tukaef May 03 '13 at 17:49
  • Combinations or Permutations? Order is important for permutations, but not so for combinations. And you want **all** such? Meaning if the set of letters is of length 5 ({a,b,c,d,e}), your going to want combinations of 5 things, taken 5 at a time, 4 at a time, 3 at a time, 2 at a time, 1 at a time? This question should start you on your way: http://stackoverflow.com/questions/127704/algorithm-to-return-all-combinations-of-k-elements-from-n – Nicholas Carey May 03 '13 at 17:50

1 Answers1

0

The easiest way is to write a recursive function with two strings, initial and output. I assume you want combinations, not permutation so it's a little easier. The base case is checking if initial is empty, then print out the output. The step is removing a character from initial and calling the recursive function twice, one with the unchanged output and one with the removed character added into the output. If the removed character is 0, however, then you only call the function once (removing the 0 without adding anything to the output.)