Mi objetivo final es convertir el código siguiente en python en C#, pero me gustaría hacerlo yo solo aprendiendo la sintaxis de python. Entiendo que el código es recursivo.Python a C# Explicación del código
El código produce polinomios de grado n con k variables. Más específicamente, la lista de exponentes para cada variable.
def multichoose(n,k):
if k < 0 or n < 0: return "Error"
if not k: return [[0]*n]
if not n: return []
if n == 1: return [[k]]
return [[0]+val for val in multichoose(n-1,k)] + \
[[val[0]+1]+val[1:] for val in multichoose(n,k-1)]
Aquí es la conversión que tengo hasta ahora:
public double[] MultiChoose(int n, int k)
{
if (k < 0 || n < 0)
{
throw new Exception();
}
if (k == 0)
{
return [[0]*n]; // I have no idea what the [[0]*n] syntax means
}
if (n == 0)
{
return new double[0]; // I think this is just an empty array
}
if (n == 1)
{
return new double[1] {k}; // I think this is just an empty array
}
//Part I don't understand
return [[0]+val for val in MultiChoose(n-1,k)] + \
[[val[0]+1]+val[1:] for val in MultiChoose(n,k-1)]
}
Mi pregunta es: ¿Cómo se convierte el código Python?
Entonces, ¿cuál es tu pregunta? –