User:Kiken/Construction Site/Implementations/横

From Esolang
Jump to navigation Jump to search
def heng(code):
    code = code.split('\n')
    for index, line in enumerate(code):
        code[index] = [ch for ch in line]
    x, y = 0, 0
    x_velocity, y_velocity = 0, 1
    while True:
        y += y_velocity
        x += x_velocity
        try:
            code[y][x]
        except IndexError:
            break
        if code[y+1][x] != '#' or '∆':
            y_velocity = 1
        else:
            y_velocity = 0
        if code[y][x+1] == '#' or '∆':
            x_velocity = 0
        if code[y-1][x] == '#' and y > 1:
            y_velocity = -1
        if code[y][x] == '~':
            break
# working on it