Jump to content

Is this possible and can you help


bradL

Recommended Posts

I don't know many languages and the ones I do know, I know very little. So here is my question. I'm trying to list all possible combinations of a code. The code has 5 blocks and each block is different, but I know the blocks just not the order they go in. Can someone help with this

Link to comment
Share on other sites

findCombination(blocks) {

if(blocks.length > 0) {

foreach(block in blocks) {

newcombs = findCominbation(blocks.remove(block));

foreach(comb in newcombs) {

result[] = block + comb;

}

}

return result;

} else {

return null;

}

You'll want something like this.

Link to comment
Share on other sites

Can you add some details/examples?

Let's say the code given is scrambled, just the blocks are out of order. For example they give you DDDDD-EEEEE-AAAAA-CCCCC-BBBBB and the correct code is AAAA-BBBB-CCCC and etc. They only way to check to see if the order is right is by filling it in on a certain website.

Link to comment
Share on other sites

Let's say the code given is scrambled, just the blocks are out of order. For example they give you DDDDD-EEEEE-AAAAA-CCCCC-BBBBB and the correct code is AAAA-BBBB-CCCC and etc. They only way to check to see if the order is right is by filling it in on a certain website.

Then you'll want the power set.

Check the coding challenges thread, I set a challenge to find the power set and there was a number of submissions, including my own solution.

Link to comment
Share on other sites

Ok thanks, I checked the thread and I'm gonna use the C++ one someone submitted

 int values[4] = { 2, 3, 5, 7 };
  set_type test_set(values, values+4);

I don't know much C++, so would this section be the only one I change

 int values[5] = { AAAAA, BBBBB, CCCCC, DDDDD, EEEEE };
  set_type test_set(values, values+5);

To something like this?

I did that but got error, it gives the blocks I enter as the undelcared identifier.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...