LoginSignup
1
1

More than 5 years have passed since last update.

第6回オフラインリアルタイムどう書くrubyでの解答

Posted at

現場での解答。ひどい・・
問題は
http://nabetani.sakura.ne.jp/hena/ord6kinship/

GEN = [1, 2, 5, 14] 

def gen(n)
  GEN.each_with_index do |e, i|
    return i - 1 if n < e
  end
  3
end

def solve(q)
  x, y = q.split('->').map(&:to_i)
  return 'me' if x == y
  gx = gen(x)
  gy = gen(y)
  xw = (x - GEN[gx]) / 3
  yw = (y - GEN[gy]) / 3
  if gx == gy
    if xw == yw
      return 'si'
    elsif gx >= 2 and xw / 3 == yw / 3
      return 'co'
    end
  elsif (gx - gy).abs > 1
    return '-'
  elsif gx > gy
    if xw + GEN[gx-1] == y
      return 'mo'
    elsif  gx >= 2 and xw / 3  == yw
      return 'au'
    end
  else
    if yw + GEN[gy-1] == x
      return 'da'
    elsif  gy >= 2 and yw / 3 == xw
      return 'ni'
    end
  end
  '-'
end

DATA.readlines.each do |line|
  no,q,a = line.chop.split(/\s+/)
  ans = solve(q)
  print no + "\t"
  print ans
  puts ans == a ? 'o' : 'x'
end
__END__
0   5->2    mo
1   28->10  au
2   1->1    me
1
1
1

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
1
1