• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generate new generation binary // need help  RSS feed

 
Nattakan Lukkanapinit
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my code



This part that i can't figure it out
I don't know how to implement this
"void PropagateNewGeneration() - this is the workhorse helper function. It will use the two private members this_gen and rule[], and create the next generation from them. This method implements a boundary condition that forces the two extreme positions of each generation to be off (i.e., " "). There are other boundary conditions choices, and this is not the one that will give us unlimited growth, but it has a simplifying effect that keeps the action contained to the width of the seed String. Recall that we took the seed and added a blank before and after that String. This will result in a String that is 2 longer than the seed. Since the rule always contracts the String by two cells (think about it) this means you need to tag-on blanks, again, to both ends of new generation. Add two blanks, apply the rule, add two blanks, apply the rule, etc. This keeps the length of each generation fixed at (the length of the seed) + 2. As I said, this is not the best theoretical boundary condition, but it is an easy one to implement."


 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not need to use all the if statements; you can simply assign the booleans from the & statement and == 0 or != 0.
Why are you using & 6 or & 7. Surely you mean & 1 << 6? You will need to check the precedences of the operators in the Java™ Tutorials or elsewhere. [Note that page calls something "logical" which is called "conditional" on another page; "conditional" is correct.]

Not sure what the specification for the PropagateNewGeneration means; that will follow from what you have been taught in your lectures. Maybe somebody else will know.

Are you copying the method names incorrectly, or is your teacher spelling them in non-Java fashion with capital letters and _?
 
Nattakan Lukkanapinit
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't get it work.

This is the step by step to generate new generation
-- PropagateNewGeneration()
3. Convert first_gen (or) this_gen string to string of 0's and 1's
4. Loop through triplets of current string, moving over one char with each loop, for 0 through MAX_LEN-1
5. Determine triplet using shift operator and inner loop: appending each of the three chars into a temp variable
6. Convert each binary triplet to a decimal equivalent
7. Look up tiplet's decimal equivalent 'n' against rules[n] to get new this_gen char for each step in the outer loop
8. Append zero to new this_gen StringBuffer variable
9. Append new char value to with each successive step through outer loop
10. Append zero to this_gen StringBuffer at end of outer loop
11. Convert this_gen back to '*' and ' '
12. Print this_gen to screen
13. Return to step 3 and iterate through all remaining generations as determined by num_generations


This is my code so far :
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is going wrong?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!