Help us understand the problem. What is going on with this article?

第19回オフラインリアルタイムどう書くの参考問題をRubyで解く

More than 5 years have passed since last update.

問題は
http://nabetani.sakura.ne.jp/hena/ord19sanwa/

def solve(q)
  nums = q.split(',').map(&:to_i)
  max_num = nums.max
  sums = []
  (1..max_num).each {|x|
    (x..max_num).each {|y|
      (y..max_num).each {|z|
        sum = [x,y,z,x*2,y*2,z*2,x*3,y*3,z*3]
        [x,y,z].combination(2){|a,b|
          sum << a + b
        }
        [x,x,y,y,z,z].combination(3){|a,b,c|
          sum << a + b + c
        }
        if ((nums & sum) == nums)
            sums << [x,y,z]
        end
      }
    }
  }
  case sums.size
  when 0
    'none'
  when 1
    sums[0].join(',')
  else
    'many'
  end
end

puts Time.now
DATA.readlines.each do |line|
  no,q,a = line.chop.split(/\s+/)
  ans = solve(q)
  print no + "\t" + ans
  puts ans == a ? ' o' : ' x'
end
puts Time.now

__END__
0   3,11,12,102,111,120 1,10,100
1   10,20,30,35,70  many
2   1,5,20,80   none
3   1,2,3,4,5,6,7,8,9,10,11,12,13,14    many
4   1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 1,4,5
nidouchi
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした