Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Permutations - upper case and lower case

 
Liza Zapson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a string of upper and lower case characters. Where the letters in the string stay in the same position. For example if the sting is ABC the result would be the following.

abc
ABC
Abc
ABc
aBc
aBC
abC
AbC

Any thoughts would be appreciated. Thanks, Lisa

 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Write down how you are going to do it. I suggest you try a recursion:

write the first letter-write the second letter-change the second letter-back

But that is only a small part of it.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liza Zapson wrote:
abc
ABC
Abc
ABc
aBc
aBC
abC
AbC

It may be of interest to notice that since the letters don't change, the only thing that matters is the case'. so what you have could also be conveyed as

LLL
UUU
ULL
UUL
LUL
LUU
LLU
ULU

I could replace these with numbers....L=0, U=1...

000
111
100
110
010
011
001
101

and then re-arrange those into

000
001
010
011
100
101
110
111

Maybe this give you an idea how to proceed...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic