directions = File.open(ARGV[0], &:readlines).map(&:chomp) n = directions.shift.to_i x1 = 0 y1 = 0 x2 = 0 y2 = 0 n.times do |i| case directions[i] when 'north' then y1 -= 1; y2 += 1 when 'northeast' then x1 += 1; y1 -= 1; x2 -=1; y2 += 1 when 'east' then x1 += 1; x2 -= 1 when 'southeast' then x1 += 1; y1 += 1; x2 -= 1; y2 -= 1 when 'south' then y1 += 1; y2 -= 1 when 'southwest' then x1 -= 1; y1 += 1; x2 += 1; y2 -= 1 when 'west' then x1 -= 1; x2 += 1 when 'northwest' then x1 -= 1; y1 -= 1; x2 += 1; y2 += 1 end end x = (x2 - x1).abs y = (y2 - y1).abs z = Math.sqrt(x**2 + y**2).round puts(((z % 26) + 'a'.ord).chr)