Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

key with combinations

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create keys with different combinations.
Let's say i have two params(a, b), then the keys would be like this:
a||
|b|
a|b|

If i have 3 params(a,b,c), then the keys would be like this:
a|b|c|
a|||
a||c|
a|b||
|b|c|
|b||
||c|

Could anyone please guide me that when the code know how many params, it will return me keys with the valid combination?

 
Amit Bhargava
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm getting this correctly, given a set of arguments, you put | after each param.
After this you remove one or more original params from the string in order to get the keys.
The keys then have to be returned in an array/vector.

Firstly, do you need to have two separate params (a&b) in the first example? If you have an array, will that suffice?
Once you have an input array, the steps may become a lot clearer.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Sonia wrote:I want to create keys with different combinations.
Let's say i have two params(a, b), then the keys would be like this:
a||
|b|
a|b|

That looks a lot like


If i have 3 params(a,b,c), then the keys would be like this:
a|b|c|
a|||
a||c|
a|b||
|b|c|
|b||
||c|


And that looks a lot like


That's a HUGE hint, by the way.
 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My concern is that i could have anything in a like 23 and in b like 12333. I want to pass a key already made like this 12|123|123| and when for a and b(the combinations i am looking for), i want the program to append it and create combinations like this:

12|123|123|a||
12|123|123||b|
.....


How is this possible, i am not able to think through it fully.

Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you are trying to do exactly. you have an existing key, like 12|123|123|. Now you are saying you are adding two new fields/pieces, like 'a' and 'b'?

so you will pass a string in, and return an array of strings. Your method will use Jeff's HUGE HINT to generate all the possible things you want to add on. Then you can create a bunch of new Strings by concatenating the passed in string with all the new ones you create.

or have we completely misunderstood what you are trying to do?
 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

yes i will pass a string to a method and let's say two more params

inputString(String input, String param1, String param2)

the output of this method would be
String input | String param1 | |
String input | | String param2|
String input |||

Appreciate any inputs on this.

Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Sonia wrote:hi,
the output of this method would be
String input | String param1 | |
String input | | String param2|
String input |||

Why not
String input | String param1 | String param2 |

Why is that one left off?

I'll re-iterate what I said before. There are two pieces. your method needs to build all the possible pieces that can be added on, like this:
|||
param1||
||param2|
|param1|param2|

and then, for each one, it needs to append it onto the end of 'input'.

Note that you probably don't want a method signature of "inputString(String input, String param1, String param2) ". If you did it that way, you'd need a new method every time you wanted to add another param...

inputString(String input, String param1, String param2, String param3)
inputString(String input, String param1, String param2, String param3, String param4)
inputString(String input, String param1, String param2, String param3, String param4, String param5)
etc...

you probably want

inputString(String input, String [] pieces)

Then you write your method to process the pieces array.
 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fred,

Yes you are right and thanks for the tips, but i am still not sure how to implement it. Any tips would be great.

Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok...it works better around here if you

  • ask specific questions
  • post your code so far
  • tell us what you expect your code to do
  • tell us what your code does

  • Generic questions like "I need help" or "show me how to do this project" are generally met with silence. Right now, it looks like you have put zero effort into doing this. If you have put in zero effort, why do you expect anyone else to put in any more effort?

    You've been given several suggestions throughout this thread, and only come back with "yeah, I need help writing this code".

    My first suggestion would be to try writing SOMETHING...ANYTHING...to at least get started.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic