# :count は、先頭から続く、5の数 Result = Struct.new( :num, :md5, :count )
res = ( "000".."300" ).each_with_object( Result.new( nil, nil, -1 ) ) do |num, res| md5 = Digest::MD5.hexdigest( num ) # ハッシュ化
md5.each_char.with_index do |char, idx| # 1文字ずつ処理する if char != "5" if idx > res.count # 大きい時だけ更新する res.num = num res.md5 = md5 res.count = idx end break end end end