Amidakuji is a method of lottery designed to create random pairings between two sets comprised of an equal number of elements.
Your task is to write a function amidakuji that returns the final positions of each element. Note that the elements are an ascending sequence of consecutive integers starting with 0 (from left to right).
Input
Your function will receive an array/list of equal-length strings consisting of 0 and 1 characters; this represents the "ladder" structure. The 1s represent the rungs of the ladder and the 0s represent empty space.
Each element begins at the top of its corresponding vertical rail, as illustrated in the diagram below.During the descent of the ladder, whenever a vertical rail intersects a horizontal rung, it swaps values with the adjacent connecting vertical rail.
Output
Your function should return an array of integers, with each integer in its final position.
Test Example

The diagram above is a visual representation of the test example below. The yellow highlighted path shows the path taken by the 2 value. Each time it encounters a crosspiece, it shifts position.

```python
ladder = [
        '001001',
        '010000',
        '100100',
        '001000',
        '100101',
        '010010',
        '101001',
        '010100'
]

amidakuji(ladder) # [4, 2, 0, 5, 3, 6, 1]
```

Other Technical Details

A function visualizer is preloaded to help illustrate the structure of the ladder; you can call this function with test inputs
No two rungs will ever be adjacent (so there is no ambiguity about directional path)
Full Test Suite: 10 fixed tests and 100 randomly-generated tests
Test input dimension upper bounds:

maximum width: 20
maximum height: 50


Inputs will always be valid

If you enjoyed this kata, be sure to check out my other katas

Difficulty: introductory

Starter code:

def amidakuji(ar):
	

Solutions:
def amidakuji(ar):
    numbers = list(range(len(ar[0])+1))
    for line in ar:
        for i, swap in enumerate(line):
            if swap == '1':
                numbers[i], numbers[i+1] = numbers[i+1], numbers[i]
    return numbers

def amidakuji(ar):
    #your code goes here. you can do it!
    # uncomment the line below to view the structure of the test case
    # print(visualizer(ar))
    width = len(ar[0])
    current = [i for i in range(width + 1)]
    for i in ar:
        layer = i
        count = 0
        for s in layer:
            if s == "1":
                current = swap(current, count, count + 1)
            count += 1
    return current
            
    
def swap(l, pos1, pos2):
    l[pos1], l[pos2] = l[pos2], l[pos1]
    return l

def amidakuji(ar):
    res = [0 for i in range(len(ar[0]) + 1)]
    for i in range(len(ar[0]) + 1):
        pos = i
        for j in range(len(ar)):
            if pos != 0 and ar[j][pos - 1] == "1":
                pos -= 1
            elif pos != len(ar[0]) and ar[j][pos] == "1":
                pos += 1
        res[pos] = i
    print(visualizer(ar))
    return res

def amidakuji(ar):
    # Set up original number list
    nums = list(range(len(ar[0])+1))
    # For each layer:
    for layer in ar:
        # Swap the positions of numbers at each rung
        for pos in range(len(ar[0])):
            if layer[pos]=="1":nums[pos],nums[pos+1]=nums[pos+1],nums[pos]
    return nums

def amidakuji(arr):
    elements = list(range(len(arr[0]) + 1))
    for row in arr:
        for i, col in enumerate(row):
            if col == "1":
                elements[i], elements[i+1] = elements[i+1], elements[i]
    return elements

def amidakuji(board):
    li = [0] * (len(board[0]) + 1)
    for i in range(len(board[0]) + 1):
        c = i
        for k in range(len(board)):
            if int(board[k][c]) if c<len(board[0]) else 0 : c += 1
            elif int(board[k][c - 1]) if c>0 else 0 : c -= 1
        li[c] = i
    return li

def f(ar, col):
    for row in ar:
        if col < len(row) and row[col] == '1':
            col += 1
        elif col > 0 and row[col-1] == '1':
            col -= 1
    return col

def amidakuji(ar):
    return [f(ar[::-1], col) for col in range(len(ar[0]) + 1)]

from functools import reduce

def amidakuji(ar):
    *ints, = range(1 + len(ar[0]))
    return reduce(swap, ar, ints)

def swap(acc, rungs):
    for r, rung in enumerate(rungs):
        if rung == '1':
            acc[r : r + 2] = acc[r + 1], acc[r]
    return acc

def amidakuji(ar):
    results = [0 for i in range(len(ar[0]) + 1)]
    for i in range(len(ar[0]) + 1):
        pos = i
        for line in ar:
            move = False
            if pos > 0:
                if line[pos - 1] == '1':
                    pos -= 1
                    move = True
            if pos < len(line) and not move:
                if line[pos] == '1':
                    pos += 1
        results[pos] = i

    return results

def amidakuji(ar):
    elements = list(range(len(ar[0]) + 1))
    for row in ar:
        for i, col in enumerate(row):
            if col == "1":
                elements[i], elements[i+1] = elements[i+1], elements[i]
    return elements