File tree 2 files changed +59
-0
lines changed
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ def process ( start , row_count )
2
+ rows = [ start ]
3
+ while ( rows . length < row_count )
4
+ old_row = rows . last
5
+ new_row = [ false ] * old_row . length
6
+ new_row . each_with_index do |tile , i |
7
+ left , center , right = get_tiles ( old_row , i )
8
+ trap = ( ( left && center && !right ) || ( center && right && !left ) || ( left && !center && !right ) || ( !left && !center && right ) )
9
+ new_row [ i ] = trap
10
+ end
11
+ rows << new_row
12
+ end
13
+ puts rows . flatten . count { |r | !r }
14
+ end
15
+
16
+ def get_tiles ( old_row , i )
17
+ left = i > 0 ? old_row [ i -1 ] : false
18
+ center = old_row [ i ]
19
+ right = ( i < ( old_row . length - 1 ) ) ? old_row [ i + 1 ] : false
20
+ [ left , center , right ]
21
+ end
22
+
23
+ input = ".^^.^.^^^^"
24
+ values = input . chars . map { |c |c =="^" }
25
+ process ( values , 10 )
26
+
27
+ input = ".^^^^^.^^.^^^.^...^..^^.^.^..^^^^^^^^^^..^...^^.^..^^^^..^^^^...^.^.^^^^^^^^....^..^^^^^^.^^^.^^^.^^"
28
+ values = input . chars . map { |c |c =="^" }
29
+ process ( values , 40 )
Original file line number Diff line number Diff line change
1
+ def process ( start , row_count )
2
+ rows = [ start ]
3
+ while ( rows . length < row_count )
4
+ puts rows . length if rows . length % 100 == 0
5
+ old_row = rows . last
6
+ new_row = [ false ] * old_row . length
7
+ new_row . each_with_index do |tile , i |
8
+ left , center , right = get_tiles ( old_row , i )
9
+ trap = ( ( left && center && !right ) || ( center && right && !left ) || ( left && !center && !right ) || ( !left && !center && right ) )
10
+ new_row [ i ] = trap
11
+ end
12
+ rows << new_row
13
+ end
14
+ puts rows . flatten . count { |r | !r }
15
+ end
16
+
17
+ def get_tiles ( old_row , i )
18
+ left = i > 0 ? old_row [ i -1 ] : false
19
+ center = old_row [ i ]
20
+ right = ( i < ( old_row . length - 1 ) ) ? old_row [ i + 1 ] : false
21
+ [ left , center , right ]
22
+ end
23
+
24
+ input = ".^^.^.^^^^"
25
+ values = input . chars . map { |c |c =="^" }
26
+ process ( values , 10 )
27
+
28
+ input = ".^^^^^.^^.^^^.^...^..^^.^.^..^^^^^^^^^^..^...^^.^..^^^^..^^^^...^.^.^^^^^^^^....^..^^^^^^.^^^.^^^.^^"
29
+ values = input . chars . map { |c |c =="^" }
30
+ process ( values , 400000 )
You can’t perform that action at this time.
0 commit comments