Discusiones sobre Productos NI

cancel
Showing results for 
Search instead for 
Did you mean: 

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
Message 1 of 4
(582 Views)

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. 

0 Kudos
Message 2 of 4
(526 Views)

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".

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 3 of 4
(518 Views)

@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

 

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 4
(511 Views)