私は Project Euler の質問 4 のプログラムに取り組んでいました - 3 桁の倍数の中で最大の回文を見つけます。これは私が書いたものです:
def palintest(number)
num = number.to_s
len = num.length
if len % 2 != 0
num[(len/2).floor] = ''
end
if num[0.. (len/2)-1] == num [len/2..len].reverse!
return number
end
end
palindromes = []
for i in 100..999
for j in 100..999
palindromes << palintest(i*j)
end
end
puts palindromes.max
次のようなエラーが表示されました。
comparison of Fixnum with nil failed
(repl):24:in `each'
(repl):24:in `max'
(repl):24:in `initialize'
何が起こっているのかよくわかりません。プログラムの各コンポーネントをテストしましたが、正常に動作しているようです。どんな助けでも大歓迎です。