Hey, Path Finder, where are you?

## Path Finder Series:
-       [#1: can you reach the exit?](https://www.codewars.com/kata/5765870e190b1472ec0022a2)
-       [#2: shortest path](https://www.codewars.com/kata/57658bfa28ed87ecfa00058a)
-       [#3: the Alpinist](https://www.codewars.com/kata/576986639772456f6f00030c)
-       [#4: where are you?](https://www.codewars.com/kata/5a0573c446d8435b8e00009f)
-       [#5: there's someone here](https://www.codewars.com/kata/5a05969cba2a14e541000129)

Difficulty: interview

Starter code:

def i_am_here(path):
	

Solutions:
import re

class Me(object):
    def __init__(self): self.x, self.y, self.dx, self.dy = 0,0,-1,0
    def move(self, n):  self.x += n*self.dx ; self.y += n*self.dy
    def back(self):     self.dx *= -1 ; self.dy *= -1
    def turn(self, d):  self.dx,self.dy = (self.dy * (-1)**(d=='l'), 0) if self.dy else (0, self.dx * (-1)**(d=='r'))
    def where(self):    return [self.x, self.y]
    def __str__(self):  return f'x,y={self.x},{self.y} (dx,dy={self.dx},{self.dy})'

me = Me()

def i_am_here(path):
    for v in re.findall(r'\d+|.', path):
        if   v in 'RL': me.back()
        elif v in 'rl': me.turn(v)
        else:           me.move(int(v))
    return me.where()

import re

facing = 0                                                                  # directions - [0,1,2,3]
current_position = [0, 0]

def i_am_here(path):
    nonlocal current_position, facing
                                                                            
    movement_dict = {'r':1, 'l':-1, 'R':2, 'L':-2}                          # used to update the facing direction  
    walk_direction = {0: (-1, 0),1: (0, 1),2: (1, 0),3: (0, -1)}            # used to walk in the facing direction
    
    for l in re.findall('\d+|\D', path):
        if l.isalpha():
            facing = (facing + movement_dict[l]) % 4
        else:
            no_of_steps = int(l)
            current_position[0] += walk_direction[facing][0] * no_of_steps
            current_position[1] += walk_direction[facing][1] * no_of_steps
            
    return current_position

import re
import numpy as np

R = np.array([[0,-1],[1,0]])
d = {'R':R@R,'L':R@R,'r':R,'l':-R}
direction = np.array([1,0])
point = np.zeros(2, 'int')

def i_am_here(path):
    nonlocal direction, point
    for command in re.findall(r'(\d+|[RrLl])', path):
        if command.isdigit():
            point -= direction * int(command)
        else:
            direction = direction @ d[command]
    return list(point)

import re

x = 0
y = 0
direction = 0
directions = [(-1,0), (0,1), (1,0), (0,-1)]

def i_am_here(path):
    nonlocal x, y, direction
    for c in re.findall(r'\d+|[rlRL]', path):
        if c == 'r': direction = (direction + 1) % 4
        elif c == 'l': direction = (direction - 1) % 4
        elif c == 'R': direction = (direction + 2) % 4
        elif c == 'L': direction = (direction - 2) % 4
        else:
            dx, dy = directions[direction]
            x += int(c)*dx
            y += int(c)*dy
    return [x, y]

direction = 0
x, y = 0, 0

def i_am_here(path):
    nonlocal direction
    nonlocal x, y
    i = 0
    while i < len(path):
        rd = reldir.get(path[i])
        if rd is not None:
            direction = (direction + rd) % 4
            i += 1
        else:
            j = i
            while i < len(path) and path[i].isdigit():
                i += 1
            n = int(path[j:i])
            x += n * dx[direction]
            y += n * dy[direction]
    return [y, x]

reldir = dict(r=1, l=-1, L=2, R=2)
dx = 0, 1, 0, -1
dy = -1, 0, 1, 0


direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]
operations = {'l': +1, 'r': -1, 'L': -2, 'R': 2}
vector = 2
position = [0, 0]

def i_am_here(path):
    nonlocal vector, position
    step = 0
    for c in path:
        if c.isnumeric():
            step = step * 10 + int(c)
        else:
            if step > 0:
                position = [position[0] + direction[vector][0]*step, position[1] + direction[vector][1]*step]
                step = 0
            step = 0
            o = operations.get(c)
            vector += o
            vector %= len(direction)
    if step > 0:
        position = [position[0] + direction[vector][0] * step, position[1] + direction[vector][1] * step]
    return position


import re
moves={0:(-1,0), 1:(0,1), 2:(1,0), 3:(0,-1)}
rotate={'r':1, 'l':-1, 'R':2, 'L':2}
x,y,d=0,0,0
def i_am_here(path):
    nonlocal x,y,d
    for m in re.findall(r'(r|R|l|L|\d+)',path):
        if m.isalpha():
            d=(d+rotate[m])%4
        else:
            dx,dy=moves[d]
            x,y=x+dx*int(m),y+dy*int(m)
    return [x,y]

x = 0
y = 0
heading = 0

def plus(cpl1, cpl2, factor):
    return [cpl1[0] + cpl2[0] * factor, cpl1[1] + cpl2[1] * factor]

headings = [(-1, 0), (0, -1), (1, 0), (0, 1)]

def change_heading(heading, character):
    if character == "l":
        return (heading + 1) % 4
    if character == "r":
        return (heading - 1) % 4
    if character == "L":
        return (heading - 2) % 4
    if character == "R":
        return (heading - 2) % 4
def i_am_here(path):
    nonlocal x
    nonlocal y
    nonlocal heading
    buffnum = ""
    i = 0
    while i < len(path):
        character = path[i]
        if '0' <= character <= '9':
            buffnum += character
        else:
            if buffnum != "":
                [x, y] = plus([x, y], headings[heading], int(buffnum))
                buffnum = ""
            heading = change_heading(heading, character)
        i += 1
    if buffnum != "":
        [x, y] = plus([x, y], headings[heading], int(buffnum))
    return [x, y]

def split_path(s):
    while s:
        i = 0
        for c in s:
            if c not in "RLrl":
                break
            i += 1
            yield c
        n = 0
        while i < len(s) and s[i].isdigit():
            n = 10 * n + int(s[i])
            i += 1
        s = s[i:]
        if n:
            yield n


def turn(d, r):
    opt = [[-1, 0], [0, 1], [1, 0], [0, -1]]
    i = opt.index(d) + {"r": 1, "R": 2, "l": -1, "L": -2}[r]
    return opt[i % len(opt)]


def step(p, d, k):
    x, y = p
    dx, dy = d
    return [x + dx * k, y + dy * k]


def i_am_here(path, d={"pos": [0, 0], "dir": [-1, 0]}):
    for p in split_path(path):
        if isinstance(p, int):
            d["pos"] = step(d["pos"], d["dir"], p)
        else:
            d["dir"] = turn(d["dir"], p)
    return d["pos"]

import re

pos = [0, 0]    # pos-x is down, pos-y is right
direction = 0   # 0=up, 1=right, 2=down, 3=left

def i_am_here(path):
    commands = list(re.findall("(\d+|[lrLR])", path))
    nonlocal direction, pos
    for command in commands:
        if command.isdigit():
            steps = int(command)
            if direction % 2 == 0:
                pos[0] += steps if direction == 2 else -steps
            else:
                pos[1] += steps if direction == 1 else -steps
        elif command == "r":
            direction = (direction + 1) % 4
        elif command == "l":
            direction = (direction - 1) % 4
        else:
            direction = (direction + 2) % 4
    return pos