Ruby Quiz wrote: > [...] > This week's Ruby Quiz is to write a program that accepts up to three parameters: > the rule as an integer in decimal, the number of steps to simulate, and the > starting state of the cells as a String of ones and zeros. not much time so nothing facing here: ---------------------------------------------------------------------------- require 'enumerator' puts("usage: ruby q134.rb [rule] [count] [start]") || exit if ARGV.size != 3 rule, count = ARGV.shift.to_i, ARGV.shift.to_i start = [0]*count + ARGV[0].split('').map{|i|i.to_i} + [0]*count (0..count).inject(start) do |l, nr| puts l.inject("#{nr}:".rjust(3)){|s, i| s + [' ', '#'][i]} (l[0,1] + l + l[-1,1]).enum_cons(3).map{|a,b,c| rule[a*4+b*2+c]} end ---------------------------------------------------------------------------- i doubled the last and first item from each line - this seems to create more consistent results with the inverted patterns than just assuming they are 0: >ruby q134.rb 129 20 1 0: # 1:################### ################### 2:################## # ################## 3:################# ################# 4:################ ##### ################ 5:############### ### ############### 6:############## ## # ## ############## 7:############# ############# 8:############ ############# ############ 9:########### ########### ########### 10:########## ## ######### ## ########## 11:######### ####### ######### 12:######## ###### ##### ###### ######## 13:####### #### ### #### ####### 14:###### ## ## ## # ## ## ## ###### 15:##### ##### 16:#### ############################# #### 17:### ########################### ### 18:## ## ######################### ## ## 19:# ####################### # 20: ###### ##################### ###### cheers Simon