LoginSignup
0
0

More than 5 years have passed since last update.

第六回オフラインリアルタイムどう書くの参考問題をRubyで解いてみた。

Last updated at Posted at 2012-12-28

第六回オフラインリアルタイムどう書くの参考問題

Rubyで解いてみました。
掛かった時間は45分ぐらい。読みづらいコードになってますが勘弁を。
解説は後で書くかも……

#!/usr/bin/ruby
#-*- Coding:UTF-8 -*-

input = gets.chomp.split(",").map{|x| x.split("-") }
square = []
2.times do |i|
    t = []
    2.times do |j|
        t[j] = input[i].map{|x| x[j].to_i}
        t[j].unshift(t[j].delete_at(1))
        t[j] = [t[j][0,2], t[j][1,2]].map(&:sort).map{|x| [*x[0]..x[1]]}
    end
    s = []
    2.times do |j|
        s[j] = t[0][j].product(t[1][j])
    end

    square[i] = s[0] | s[1]
end

puts (square[0] & square[1]).size
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0