Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. String rule(char a, char b, char c){
  2. String rval = "0";
  3. if(a!=c){
  4. rval = "1";
  5. }
  6. return rval;
  7. }
  8. char fancyGet(int index){//gets a value from old at a given position
  9. if(index>=0){
  10. return old.charAt(index%(old.length()));
  11. } else {
  12. return old.charAt(old.length()-1);
  13. }
  14. }
  15. void run(){//the method that executes the rule
  16. old=program;//save the old program and begin mutation
  17. program = "";//empty the current program
  18. for(int i = 0; i < old.length(); i++){
  19. program = program + rule(fancyGet(i-1),fancyGet(i),fancyGet(i+1));
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement