Discusiones sobre Productos NI

cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 

Ejercicio de permutaciones

Necesito generar todas las posibles permutaciones de un numero entero de cuatro digitos. Ejm: 7812, permutaciones son 8172,7821,2871,etc

 

I need to generate all possible permutations of a four digit integer. Ex: 7812, permutations are 8172,7821,2871, etc.

0 kudos
Mensaje 1 de 4
4.093 Vistas

Este no es un foro para cumplir deseos de usuarios.

 

Se trata de apoyar en dudas, guiar y aconsejar.

 

"Necesito hacer X cosa" no menciona cuál es tu problema o duda. Tampoco compartes tus intentos o código que has hecho hasta el momento. 

=======
My Channel: https://www.youtube.com/@LV_Lab

0 kudos
Mensaje 2 de 4
4.037 Vistas

Format as string and separate into an array of single digits, then start reading here. Scan back into numeric if desired.

 

Is it always four digits or can it be any number of digits? For very long inputs, you might run out of memory.

 

(Of course if some values are in duplicate, you need to filter at the end to only retain the unique results (e.g. 7745 has duplicates while an input of 4444 only has exactly one solution). removing duplicates is easy, though. See how far you get. You could even avoid storing duplicates by accumulating results into a "set".

 

0 kudos
Mensaje 3 de 4
4.029 Vistas

@altenbach wrote:

You could even avoid storing duplicates by accumulating results into a "set".


Here's how that could look like (requires LabVIEW 2019 or newer):

See if you can recreate it 😉

 

altenbach_0-1592076108330.png

The use of a set correctly eliminates duplicates:

 

altenbach_1-1592076213872.png

 

 

0 kudos
Mensaje 4 de 4
4.022 Vistas