PDA

View Full Version : C++ algorithm help ...

Nuticulus
August 11th, 2009, 09:41 AM
Hi,

I have a "row" class with members pixels[200], int numPixels, and int offset, and an "order" class with members int ord[100] and int off[100].

I also have 2 arrays of rows, row Good1[height] and row Unscrambled[height], of which only the first NumGood1 (int) elements are defined.
Also there is an order object o, where ord[] and off[] are only defined from 0 to NumGood1 inclusive.

I need an algorithm that:

Only changes the values of Unscrambled[]
Tries to copy elements from Good1[] into Unscrambled[] so that Unscrambled[x].numPixels == o.ord[x] and Unscrambled[x].offset == o.off[x]
Will, if called repeatedly, cycle through all possible solutions.

Thankyou very much. I have been racking my brains out on this, so I hope someone is cleverer than I am. ;)

nvteighen
August 11th, 2009, 10:31 AM
Hi,

I have a "row" class with members pixels[200], int numPixels, and int offset, and an "order" class with members int ord[100] and int off[100].

I also have 2 arrays of rows, row Good1[height] and row Unscrambled[height], of which only the first NumGood1 (int) elements are defined.
Also there is an order object o, where ord[] and off[] are only defined from 0 to NumGood1 inclusive.

I need an algorithm that:

Only changes the values of Unscrambled[]
Tries to copy elements from Good1[] into Unscrambled[] so that Unscrambled[x].numPixels == o.ord[x] and Unscrambled[x].offset == o.off[x]
Will, if called repeatedly, cycle through all possible solutions.

Thankyou very much. I have been racking my brains out on this, so I hope someone is cleverer than I am. ;)

Heck... can you please tell us what your code is supposed to do? (the task... what's your goal) Because, at first sight, I tend to think this is all overkill.

Anyway, some ideas (these ideas are language-independent):

If you want Good1 to be really untouched, copy-construct the stuff when copying into Unscrambled. Don't pass a reference.
The second part is trivial. Hell, you have written it almost by yourself!
Ok, try using static variable to hold state across stack calls. But I'm not sure there are more than one single solution, is there?

Nuticulus
August 11th, 2009, 10:46 AM