LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

combination code

hello i need the code for combinations for given string for eg if the input string is abcd then the o/p contains all 24 combinations pls help me
0 Kudos
Message 1 of 8
(3,341 Views)

Hi jeshu,

 

this really sounds like homework. I think I saw that question before...

 

We will not do your homework here, but we will be happy to help for specific questions. So show what you have done before & tell where you have problems!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,339 Views)
actually i dont know the algorithm how to do this , i am searching for idea not whole code sir , i know something that we need to convert the string in to byte array then i am not getting any idea for what to do , pls help me this pro is coming for  tomorrow's test
0 Kudos
Message 3 of 8
(3,334 Views)

Hi jeshu,

 

in the string palette you find a function to convert a string into an U8 array.

 

For the theory you may start here!

 

Good luck for tomorrow's test - I will now enjoy my Sunday evening Smiley Wink

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 8
(3,330 Views)
This sounds like a job for recursion, unless you're limiting the input to only four characters.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 5 of 8
(3,318 Views)

Hi jeshu

 

This is not a difficult code to make. I have already done this. 

Start like this. I hope you are familiar with the for loop!

So use 4 nested for loops to compare the individulal letters and finally write them in an array. Like you have ABCD. Take A from the first loop and use it to compare with all letters in 2nd loop. As soon as you get different letters in 2nd loop (like A and B), compare these 2 letters with all letters in loop number 3. when you get all 3 different letters from loop number 3 (like A , B , C), compare all the 3 with letters in the final loop. Finally , when you have all three different letters, write them in an array.  

 

Somil Gautam
Think Weird
0 Kudos
Message 6 of 8
(3,295 Views)

Hi jeshu,

 

one more hint:

Try to adapt an recursive way of generating combinations:

1) start with 1 char -> one possibility (A)

2) add 2nd char and "insert" it before and after first char -> two additional possibilities (AB, BA)

3) add 3rd char and insert it in every possible position in each of the strings generated before -> 6 more possibilities (CAB, ACB, ABC, CBA, BCA, BAC)

4) add 4th char and repeat step 3 (DCAB, ADCB, ABCD, some more...)

5) do step 3 for all additional chars

 

This should be a nice exercise to learn how to use for loops, shift registers, building arrays and string functions Smiley Wink

Message Edited by GerdW on 11-09-2009 10:33 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 8
(3,277 Views)

Ya, this is another way of doing it.

 

In the method of nested for loops, you can get 24 combinations only if all the letters in the string are different (because of comparison)

 

But in this method, of  insertion, you can get the combinations even if the letters are same in a given string. 

Somil Gautam
Think Weird
0 Kudos
Message 8 of 8
(3,273 Views)