ruby
1h_s2_n=Hash.new 2last_prop=Hash.new 3a_depth=[6,9,12,15] 4h_line_n.each{|symp,arr| 5 h_s2_n[symp]=Array.new 6 7 arr.each{|x| 8 if x[0]==6 then 9 h_s2_n[symp] << x[1][0] 10 11 end 12 } 13} 14h_line_n.each{|symp,arr| 15 a_depth.each{|d| 16 s2=0 17 arr.each{|x| 18 if x[0]==d then 19 h_s2_n[x[1][0]]=Array.new 20 s2=x[1][0] 21 elsif x[0]==d+3 && s2 > 0 then 22 if x[1][1]==0 then 23 h_s2_n[s2] << x[1][0] 24 else 25 unless last_prop[s2] then 26 last_prop[s2]=Array.new 27 end 28 last_prop[s2] << x[1][0] 29 end 30 31 end 32 } 33 } 34} 35p h_s2_n
ruby
1h_s2_n=Hash.new { |hash, key| hash[key] = Array.new } 2last_prop=Hash.new { |hash, key| hash[key] = Array.new } 3a_depth=[6,9,12,15] 4h_line_n.each{|symp,arr| 5 arr.each{|x| 6 if x[0]==6 then 7 h_s2_n[symp] << x[1][0] 8 end 9 } 10} 11h_line_n.each{|symp,arr| 12 a_depth.each{|d| 13 s2=0 14 arr.each{|x| 15 if x[0]==d then 16 s2=x[1][0] 17 elsif x[0]==d+3 && s2 > 0 then 18 if x[1][1]==0 then 19 h_s2_n[s2] << x[1][0] 20 else 21 last_prop[s2] << x[1][0] 22 end 23 24 end 25 } 26 } 27} 28p h_s2_n
この2つの結果が変わってしまうのですが、なぜだかわかりません。
ご教授のほど、よろしくお願いします。
どのようなことがしたいプログラムかを書いていただけると考えやすいです。
あと、両コードとも未定義の h_line_n に each メソッドを実行しているのでうまく動作しないと思うのですが・・・?