20/05/23 03:35:28.55 zNKp3hWU.net
>>582 Ruby
def moves( str )
x, y = 0, 0
dx, dy = 0, -1
ts2 = %w{北 西 \ 東 南 }
str.split(/,\s*/).each{|ch|
case ch
when '1'; dx, dy = dy, -dx
when '2'; dx, dy = -dy, dx
when '3'
x += dx
y += dy
end
puts "%3d %3d %s" % [ x, y, ts2[dx + 2*dy + 2] ]
}
end
moves( "1, 3, 3, 2, 3" )
moves( "3, 2, 3, 1" )