~ :of s, and x is the set of divisors of sl.
~ :
~ :y = sl / x
~ :m = re.match("([NSEW]{%i}){%i}" % (x,y),s)
~ :
in perl I would probably do something like:
$str=~ s/N+/N/g;
$str=~ s/S+/S/g;
$str=~ s/E+/E/g;
$str=~ s/W+/W/g;
maybe there's a smarter way to do it though.