I have: 39H4-GTT7-LGLN And I'm trying to find every possible combination of sets. Basically each section is scrambled within itself. So there's only 16 combinations for each section. Example the first section I wrote it out as:

    39H4
    394H
    349H
    34H9
    49H3
    4H93
    493H
    4H39
    9H34
    934H
    943H
    9H43
    H493
    H934
    H394
    H439

I'm trying to find these for every section. At the end I think I should have 256 combinations since for each section I combine it with another section. Though I think my math is wrong :S Maybe it's (16*16)^3?

Example:

    39H4-GTT7-LGLN
    394H-GTT7-LGLN
    349H-GTT7-LGLN
    34H9-GTT7-LGLN
    49H3-GTT7-LGLN
    4H93-GTT7-LGLN
    493H-GTT7-LGLN
    4H39-GTT7-LGLN
    9H34-GTT7-LGLN
    934H-GTT7-LGLN
    943H-GTT7-LGLN
    9H43-GTT7-LGLN
    H493-GTT7-LGLN
    H934-GTT7-LGLN
    H394-GTT7-LGLN
    H439-GTT7-LGLN

And then I'd start all over for the next section but still include the first. I think this is called nfactorial or permutations or something but I'm not sure.

I started off with this code:

#include <windows.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>

using namespace std;

void UnScramble(std::string Code)
{
    std::vector<std::string> Elements;

    for (int I = 0; I < Code.size(); I++)
        if (Code[I] == '-')
            Elements.push_back(Code.substr(I - 4, 4));

    Elements.push_back(Code.substr(Code.size() - 4, 4));
}

int main()
{
    UnScramble("39H4-GTT7-LGLN");
}

before I got frustrated and erased the rest of my code and started writing them out.. So I was to start fresh with my code above but I don't know how to start getting each combination of each section and then to get each combination of all 3.. It's killing my brain.

How do I start? Or better yet Where? I think if I can figure out how to get the 16 combinations for each section, I can do the rest. I was thinking if I get each combination and store them like so:

vector<vector<string>(16)> 2DArrayOfStrings(3); so 3 sets of 16 sets of strings I can iterate it with 3 nested forloops to construct all combinations?

Recommended Answers

All 2 Replies

If you don't understand what you are writing, you should not be writing code. You need to sit at a desk with pencil and paper and plan -- yes plan -- what you need to accomplish.

Write down what the task is.
Break that description into pieces -- like in English class, what are the nouns, verbs, and the implied parts (but don't really look for nouns and verbs -- that's English class)

Write down how you accomplish each task. Then break that down into smaller pieces until you get to the point each step is as small as it can get.

There's your design. Now run through it by hand to see if it does what you want. Write down variables as they change. YOU be the computer and that description is your psuedocode.

When that's done, works, etc., now you're ready to start coding. Take a section at a time. Do the input. Get it working completely. Add the output. Get it working. Then one more step. Get it working. Add another... ad nauseum.

That's programming! (sorry, but that's really how we do it.)

The basic ideea of your problem is called a Permutation. There are numerous methods of doing that, maybe check in the CS department of the link for some concrete algorithms.

How do I start? Or better yet Where?

take WaltP's example...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.