Skip to main content
1 of 6
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68

Python 3, 109 bytes

This is a simple answer that uses complex numbers, with input as a newline-separated string, like so:

m("""R5
L5
R5
R3""")

Golfing suggestions welcome!

def m(s,d=0,p=0):
 for r in s.split():d+=(-1)**(r[0]<"R");p+=1j**d*int(r[1:])
 return abs(p.real)+abs(p.imag)

Ungolfing

def manhattan_rotation(seq, nsew=0, pos = 0):
    for rot in seq.split():
        nsew += (-1) ** (rot[0] < "R")
        pos += 1j ** nsew * int(rot[1:])
    return abs(pos.real)+abs(pos.imag)
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68