スコアは以下のものを使う。
irb(main):122:0> alignment "abcdea","aebcdbae" a-bcdea- aebcdbae => 5 irb(main):123:0> alignment "aaabb","baaa" aaabb baa-a => 0 irb(main):123:0> alignment "aabbbbcc","bbbbccaa" aabbbbcc-- --bbbbccaa => 4
Array.new(10,1) => [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[1,2,5,4,2].length => 5 [1,2,5,4,2].size => 5
[1,2,3,4].length => 4 a="abcde" => "abcde" a.length => 5 a.size
a="abcde" => "abcde" a[3] => 100文字「d」の文字コードは100
a="abcde" => "abcde" a[3..3] => "d"
[1,3,4].max => 4
a=Array.new(10,Array.new(10,0))のようにしてはいけない.これだと,a[0]とa[1]が同じものになるので,
a=Array.new(10,Array.new(10,0)) => [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] a[0][0]=1 => 1 a[1][0] => 1となる.
a=Array.new(10) for i in 0..9 a[i]=Array.new(10,0) endならOK.よりrubyらしく書くなら
a=(0..9).collect{Array.new(10,0)}