Created
September 10, 2015 16:49
-
-
Save trodrigu/ee3ea1c3041e1e5f84b8 to your computer and use it in GitHub Desktop.
Revisions
-
trodrigu created this gist
Sep 10, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ class Rule90 def initialize input @input = input.split(//).map(&:to_i) end def get_next target_index, input input[target_index + 1] end def get_prev target_index, input input[target_index - 1] end def evolve input input.map.with_index do |item, target_index| if target_index == 0 prev_val = 0 next_val = get_next target_index, input elsif target_index == input.length - 1 next_val = 0 prev_val = get_prev target_index, input else next_val = get_next target_index, input prev_val = get_prev target_index, input end prev_val == next_val ? 0 : 1 end end def draw_x arr row = arr.map do |item| if item == 0 " " else "x" end end puts row.join("") end def iterate_and_draw input = @input draw_x input 24.times do input = evolve input draw_x input end end end r90 = Rule90.new("00000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000") r90.iterate_and_draw