x,y = 0,0 gets.chomp.chars{|c| case c when ?N then y+=1 when ?E then x+=1 when ?W then x-=1 when ?S then y-=1 end } p Math.sqrt(x**2+y**2)