How to translate generators in this algorithm from Python to C#?

Question:

I am translating Python code to C#. Can anyone help please.

    def transpose_to_hilbert_integer(self, x:list) -> int: # x is a list of ints
    """Restore a hilbert integer (`h`) from its transpose (`x`).

    Args:
        x (list): transpose of h
            (n components with values between 0 and 2**p-1)

    Returns:
        h (int): integer distance along hilbert curve
    """
    x_bit_str = [HilbertsCurve._binary_repr(x[i], self.p) for i in range(self.n)]
    print(x_bit_str)
    h = int(''.join([y[i] for i in range(self.p) for y in x_bit_str]), 2)
    return h

Translating to this:

public int Transpose_to_hilbert_integer(List<int> x)
    {
        List<string> x_bit_str = new List<string>();
        for (int i = 0; i < this.n; i++)
        {
            x_bit_str.Add(HilbertsCurve._binary_repr(x[i], this.p));
        }

// second part of the code. Make h.
        return h;
    }

Stuck of the double list comprehention

Asked By: Red Mermaid

||

Answers:

I did it, I used a normal nested for loop instead in C#. Double nested. And += concatenation instead of .join() to an empty string.

Answered By: Red Mermaid
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.