Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. 010,101,010
  2.  
  3. 010101010
  4.  
  5. 010
  6. 101
  7. 010
  8. 3 010101010
  9.  
  10. 010
  11. 101
  12. 010 Evolved
  13.  
  14. 0101110100
  15. 0010101001
  16. 1011100110
  17. 0101111101
  18. 1001001111
  19. 1111001001
  20. 1011111010
  21. 0110011101
  22. 1001010100
  23. 0010111010 Created
  24.  
  25. import java.util.Arrays;
  26. public class z{
  27. static boolean u=true,v=false;
  28. public static void main(String[] a){
  29. int y=a.length,x=a[0].length();Boolean[][] l=new Boolean[x][y];for(int i=0;i<a.length;i++){l[i]=m(a[i]);}
  30. Boolean[] n=new Boolean[x*y];for(int i=0;i<n.length;i++){n[i]=v;}
  31. while(n.length==x*y){Boolean[][] o=new Boolean[x][y];for(int i=0; i<n.length;i++){o[i%x][i/x]=n[i];}
  32. n=p(n);o=q(o,x,y);int r=0;for(int i=0;i<x*y;i++){if(o[i%x][i/x]&&l[i%x][i/x])r++;}
  33. if(r==x*y){System.out.println("evolved");return;}}System.out.println("created");}
  34. public static Boolean[][] q(Boolean[][] o,int bx,int by){Boolean[][] s=new Boolean[bx][by];for(int x=0; x<bx; x++){for(int y=0;y<by;y++){
  35. int t=0;for(int tx=-1;tx<2;tx++){for(int ty=-1;ty<2;ty++){if(ty+y<0||ty+y>by-1||tx+x<0||tx+x>bx-1)continue;if(o[tx+x][ty+y]){t++;}}}
  36. if(t>1&&t<4){s[x][y]=u;}else{s[x][y]=v;}}}return s;}
  37. public static Boolean[] p(Boolean[] b){boolean w=u;Boolean[] x=new Boolean[b.length];for(int i=0;i<b.length;i++){if(w&&b[i]){x[i]=u;w=u;}else if(b[i]||w){x[i]=u;w=v;}else{x[i]=v;w=v;}
  38. }if(w){x=Arrays.copyOf(x,x.length+1);x[x.length]=u;}return x;}
  39. public static Boolean[] m(String s){Boolean[] x=new Boolean[s.length()];for(int i=0;i<s.length();i++){x[i]=s.charAt(i)=='1';}return x;}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement