New Reply

C#: Changing Values In an Array

 
Share Thread Thread Tools
Dec1-12, 09:27 PM   #18
 

C#: Changing Values In an Array


Quote by rcgldr View Post
For now only use the number of loops that equals the number of letters, for two letters, just two loops.

I'll have to search my old files for my combination and permutation stuff, and even though this code may be more generic, it may not be faster. I'll post an update later when I find this and figure it out.

If you've got to dig through old files to figure it out I won't put you through the trouble. I figured out how to use continue and I'm getting the correct answers with much faster computation times, only it is printing out the results twice for some reason. I have enough done at this point that I can take it in to my professor and work out that one last kink.

Thank you so much for your help! I don't know that I would have finished this without hashing it out and getting ideas I wouldn't have thought of by myself. I really appreciate it.
 
Dec2-12, 06:59 AM   #19
 
Recognitions:
Homework Helper Homework Help
Quote by jellofaceman View Post
If you've got to dig through old files to figure it out.
I found my example programs, but these involve algorithms that are non-obvious and beyond what you'd be expected to know in class. I'm not sure how the professor expected students in your class to generate combinations and permulations other than the brute force method of using nested loops, which you already did, or a single loop with division and modulo to create a set of digits which was sugggested in this thread.

The issue with permutation algorithms is that the code itself isn't difficult to follow, but understanding why these work is much more complicated. Once you're done with this assignment, you can do a web search for "next permutation", which should get you a few web sites that show various algorithms for doing this. (Note - all of the recursive algorithms I could find generate all the permutations, but not in sequential order). I assume that in your class, the students are supposed to create their own algorithms as opposed to using algorithms they find at various web sites or references, unless the class uses a textbook that includes the algorithms the students are supposed to use.
 
Dec2-12, 08:39 PM   #20
 
Quote by rcgldr View Post
I'm not sure how the professor expected students in your class to generate combinations and permuations other than the brute force method of using nested loops, which you already did...

I assume that in your class, the students are supposed to create their own algorithms as opposed to using algorithms they find at various web sites or references...
The assignment actually tells us that we need to use a brute force method to solve the puzzles. It vaguely describes an algorithm we can implement to accomplish this; finding unique letters, assigning them all possible values 0-9, checking the value of the words against eachother.

I'll have to take a look at the "next permutation" approach once school has slowed and I get time. I'd like to know another way of solving this.

Thanks again for all your help!
 
Dec3-12, 08:25 PM   #21
 
Recognitions:
Homework Helper Homework Help
Quote by jellofaceman View Post
I'll have to take a look at the "next permutation" approach once school has slowed and I get time. I'd like to know another way of solving this.
The iterative code for next permutation is less than 20 lines of code (plus a 3 line swap function and a function called each time a permuation is generatred). The code and the algorithm are easy to follow. The issue is you'll need step through the code a few times to understand why it works. The recursive versions are even smaller, but they don't produce the permutations in "order".
 
New Reply
Thread Tools


Similar Threads for: C#: Changing Values In an Array
Thread Forum Replies
returning values in array in c Programming & Comp Sci 4
Fortran 77 making an array but changing the increment value Programming & Comp Sci 10
How to search for duplicate values in an array of integers? Programming & Comp Sci 3
converting from an array of function values to coordinate array of different length Programming & Comp Sci 3
C prog: printing values from array of structures Computing & Technology 36