This repository was archived by the owner on Mar 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Created by /u/jorgegil96 on Reddit
2
+ // Challenge #213 [Easy] Cellular Automata: Rule 90
3
+ // https://www.reddit.com/r/dailyprogrammer/comments/3jz8tt/20150907_challenge_213_easy_cellular_automata/
4
+
5
+ public class CARule90 {
6
+ public static void states (String input , StringBuilder sb ) {
7
+ int before , after ;
8
+ for (int i = 0 ; i < input .length (); i ++) {
9
+ before = 0 ;
10
+ after = 0 ;
11
+ if (i == 0 ) {
12
+ after = Character .getNumericValue (input .charAt (i + 1 ));
13
+ }
14
+ else if (i == input .length () - 1 ) {
15
+ before = Character .getNumericValue (input .charAt (i - 1 ));
16
+ }
17
+ else {
18
+ before = Character .getNumericValue (input .charAt (i - 1 ));
19
+ after = Character .getNumericValue (input .charAt (i + 1 ));
20
+ }
21
+ if ((before + after ) % 2 == 0 ) {
22
+ System .out .print (" " );
23
+ sb .setCharAt (i , '0' );
24
+ }
25
+ else {
26
+ System .out .print ("X" );
27
+ sb .setCharAt (i , '1' );
28
+ }
29
+ }
30
+ }
31
+
32
+ public static void main (String [] args ) {
33
+ String input = "00000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000" ;
34
+ StringBuilder sb = new StringBuilder (input );
35
+
36
+ int n = 25 ;
37
+
38
+ for (int i = 0 ; i < input .length (); i ++)
39
+ if (input .charAt (i ) == '0' )
40
+ System .out .print (' ' );
41
+ else
42
+ System .out .print ('X' );
43
+
44
+ System .out .println ("" );
45
+
46
+ for (int i = 0 ; i < n ; i ++){
47
+ states (sb .toString (), sb );
48
+ if (!sb .toString ().contains ("1" )){
49
+ break ;
50
+ }
51
+ System .out .println ("" );
52
+ }
53
+
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments