Click here to Skip to main content
15,911,896 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello.
I'm working on a project which in part of it I need a function which returns all possible ways to remove Capital letters of a string as a List or an Array.

For Example my string is : aAbBcCdD

The algorithm or function must return a List or an Array like this :

aAbBcCdD
abBcCdD
aAbcCdD
aAbBcdD
aAbBcCd
abcCdD
abBcdD
abBcCd
aAbcdD
aAbcCd
aAbBcd
abcdD
abcCd
abBcd
aAbcd
abcd

I searched so much about it and someone said "use a recursive function that takes the Cartesian product of all possibilities for the first letter and the function applied to the rest of the string. (If the first letter is a capital, there are two possibilities. If the first letter is lowercase, there is only one possibility.)"

I know a little bit about Recursive functions and Cartesian product but I've no idea how can I make it possible !

is there anyone who can help me ?

thanks.

What I have tried:

A l m o s t n o t h i n g :(
Posted
Updated 11-Aug-16 13:52pm
Comments
BillWoodruff 12-Aug-16 4:36am    
The reasonable expectation that you have tried more than "almost nothing" is what this forum is about. Show some effort.
Mohammad-R 12-Aug-16 4:53am    
Yes I tried some ways but what I tried are some stupid "For" statements and blah blah which I think they don't deserve to use as "What I tried" and I deleted them !
Plus , there isn't any code which I want to fix them and I don't want the code of what I need ! I need the way or algorithm or a hint about it like what ppolymorphe said.

1 solution

There is many algorithms for this problem.
you can consider that let a capital or remove it is a binary thing.
4 capitals means 2^4 possibilities. Counting from 0 to 15 (2^4-1) will match all combinations.
 0=> 0000b=> aAbBcCdD
 1=> 0001b=> aAbBcCd
 2=> 0010b=> aAbBcdD
 3=> 0011b=> aAbBcd
 4=> 0100b=> aAbcCdD
 5=> 0101b=> aAbcCd
 6=> 0110b=> aAbcdD
 7=> 0111b=> aAbcd
 8=> 1000b=> abBcCdD
 9=> 1001b=> abBcCd
10=> 1010b=> abBcdD
11=> 1011b=> abBcd
12=> 1100b=> abcCdD
13=> 1101b=> abcCd
14=> 1110b=> abcdD
15=> 1111b=> abcd

[Update]
In order to check each bit for a given value, you have to use bitwise logic operators.
(value & 8) tells you if you have to remove "A" or not.
(value & 1) tells you if you have to remove "D" or not.
3.8 — Bitwise operators « Learn C++[^]
 
Share this answer
 
v2
Comments
[no name] 12-Aug-16 1:59am    
A 5.
Patrice T 12-Aug-16 2:23am    
Thank you
Mohammad-R 12-Aug-16 4:33am    
Thanks for your answer.
You mean I use a list or an array of Binaries from 0 to ((2^n)-1) (n = number of Capital chars) which every bit in every item of array is one of my Capital chars then for each Item in list or array , I check each bit then if it was 1 then remove the capital letter in the same position ?! right ?!
BillWoodruff 12-Aug-16 4:37am    
My vote of #3. Another vague answer which will probably mystify the OP, even though it does contain a "clue."
Patrice T 12-Aug-16 5:01am    
Until now, it is the only answer. May be you can provide a better one ?
I just gave a clue because the OP have done almost nothing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900