arr = 2.times.map { gets.chomp } from, to = arr.map { %w[E W S N].index(_1) } puts((to - from).then { _1.positive? ? _1 : _1 + %w[E W S N].length })