Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 010,101,010
- 010101010
- 010
- 101
- 010
- 3 010101010
- 010
- 101
- 010 Evolved
- 0101110100
- 0010101001
- 1011100110
- 0101111101
- 1001001111
- 1111001001
- 1011111010
- 0110011101
- 1001010100
- 0010111010 Created
- import java.util.Arrays;
- public class z{
- static boolean u=true,v=false;
- public static void main(String[] a){
- 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]);}
- Boolean[] n=new Boolean[x*y];for(int i=0;i<n.length;i++){n[i]=v;}
- 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];}
- 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++;}
- if(r==x*y){System.out.println("evolved");return;}}System.out.println("created");}
- 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++){
- 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++;}}}
- if(t>1&&t<4){s[x][y]=u;}else{s[x][y]=v;}}}return s;}
- 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;}
- }if(w){x=Arrays.copyOf(x,x.length+1);x[x.length]=u;}return x;}
- 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