hi i want to display string combination on nslog like this format
abc
bca
acb
and so on
but my program show me it like this format permutations =
(
(
c,
b,
a
),
(
b,
c,
a
),
(
c,
a,
b
),
(
a,
c,
b
),
(
b,
a,
c
),
(
a,
b,
c
)
)
this is the code i am using
NSArray *array = [NSArray arrayWithObjects:@"a",@"b",@"c",nil];
NSMutableArray *permutations = nil;
int i = 0;
for (i = 0; i < array.count ; i++){
if (!permutations){
permutations = [NSMutableArray array];
for (NSString *character in array){
[permutations addObject:[NSArray arrayWithObject:character]];
}
} else {
//make copy of permutations array and clean og array
NSMutableArray *aCopy = [permutations copy] ;
[permutations removeAllObjects];
for (NSString *character in array){
//loop through the copy
for (NSArray *oldArray in aCopy){
//check if old string contains looping char..
if ([oldArray containsObject:character] == NO){
//update array
NSMutableArray *newArray = [NSMutableArray arrayWithArray:oldArray];
[newArray addObject:character];
//add to permutations
[permutations addObject:newArray];
}
}
}
}
}
NSLog(@"permutations = \n %@",permutations);
}
kindly tell me how i can display it in my require format