Ad
  • Default User Avatar

    Perhaps my description of the kata will make more sense:

    Description
    Amidakuji is a lottery method designed to create random pairs between two sets of the same size.In this kata the elements of the first set are whole numbers from 0 to 6. Your task is to write an amidakuji function that returns second set comprised of converse numbers.

    Input
    Your function will receive an array of equal-length strings consisting of 0 and 1 characters; this represents the "ladder" structure. The 1 represent the rungs of the ladder and the 0 represent empty space.

    const ladder = [
        '001001',
        '010000',
        '100100',
        '001000',
        '100101',
        '010010',
        '101001',
        '010100'
    ];
    
    amidakuji(ladder); // [4, 2, 0, 5, 3, 6, 1]
    

    Take a look at the diagram below:

    Row 0 of the ladder is '001001' string, which means there will be two horizontal bridges at this row; one between the vertical lines 2 and 3 and another between vertical lines 5 and 6. When proceed to move down vertical lines, a transition is made to the adjacent vertical line over the nearest bridge.

    Output
    The diagram above is a visual representation of ladder argument of the function.
    At the top of the diagram the 2 has a third position, in the aftermath of the ladder it got a second position. The yellow highlighted path shows the path taken by the 2 value. Every time it encounters a bridge, it moves to the opposite vertical line.

    Your function should return an array of numbers, with each number in its final position.