Although what I tried is in c++, I guess you will get the logic. I was stuck in the same question so I searched around and this is what I ended up writing...I know it is not perfect and I would love if someone helps me make this code better and point out my mistakes.
#include <bits/stdc++.h>
using namespace std;
string decToBinary(int n,int l)
{
string ret="";
for (int i = l-1; i >= 0; i--) {
int k = n >> i;
if (k & 1)
ret=ret+"1";
else
ret=ret+"0";
}
return ret;
}
int main()
{
string x;
cin>>x;
transform(x.begin(), x.end(), x.begin(), ::tolower);
int size=x.length();
string bin;
for(int i=0;i<pow(2,size);i++)
{
bin=decToBinary(i,size);
for(int j=0;j<size;j++)
{
if(bin[j]=='1')
cout<<(char)(x[j]-32);
else
cout<<x[j];
}
cout<<endl;
}
}
Suppose the word "dog"...so, there will be 2^(number of letters) i.e. 2^3=8 combination. So, in this program, we iterate from 0-7 and convert the iterator(i in this case) to binary, for example, take the fifth iteration the binary would be 101 then the resultant word would be DoG (taking 1 as upper case and 0 as the lower case)..like this you can get all 2^n resultant words.