function directionSequence(i, dim) { // :: Int -> Int -> Int
    if (i == 0) return 0
    if (i % 2 == 0) return bitwise.trailingSetBits(i - 1) % dim
    return bitwise.trailingSetBits(i) % dim
}
function directionSequence(i, dim) { 
    if (i == 0) return 0
    if (i % 2 == 0) return bitwise.trailingSetBits(i - 1) % dim
    return bitwise.trailingSetBits(i) % dim
}
function directionSequence ( i , dim ) { // :: Int -> Int -> Int if ( i == 0 ) return 0 if ( i % 2 == 0 ) return bitwise . trailingSetBits ( i - 1 ) % dim return bitwise . trailingSetBits ( i ) % dim }
calculate direction at each iteration
calculate direction at each iteration