bradL Posted February 27, 2009 Share Posted February 27, 2009 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 Quote Link to comment Share on other sites More sharing options...
xdmag Posted February 27, 2009 Share Posted February 27, 2009 Can you add some details/examples? Quote Link to comment Share on other sites More sharing options...
stingwray Posted February 27, 2009 Share Posted February 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
bradL Posted February 27, 2009 Author Share Posted February 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
stingwray Posted February 27, 2009 Share Posted February 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
bradL Posted February 27, 2009 Author Share Posted February 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
stingwray Posted February 27, 2009 Share Posted February 27, 2009 Well AAAAA isn't an integer and you saying that it is an array of integers. Quote Link to comment Share on other sites More sharing options...
bradL Posted February 27, 2009 Author Share Posted February 27, 2009 Good point, the code would contain a mixture of letter and numbers. The letters will be all cap though, so how could I adapt the code to be able to handle it. Quote Link to comment Share on other sites More sharing options...
stingwray Posted February 27, 2009 Share Posted February 27, 2009 Well if you don't care about adding numbers together etc. just using strings will be fine and you can compare them later. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.