Skip to main content
3 of 6
Editing the answer
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68

Python 3, 109 bytes

This is a simple answer that uses complex numbers, with input as a space-separated string or a newline-separated string. 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():
        # change direction
        if rot[0] == "L":
            nsew += -1 
        else:
            nsew += 1
        # move in that direction rot[1:] times
        pos += 1j ** nsew * int(rot[1:])
    return abs(pos.real)+abs(pos.imag)
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68