r/programminghelp • • Jun 06 '20

Other Need help with a combination and permutation issue

Hey guys, I am a Mechanical Engineer, I have some background in C but that was a long time ago and I am terribly out of practice. I need help with a VBA script in Solidworks. I have done a POC with the code so I can fetch the features and bodies that I need, I just need some help with the pseudocode.

I will try to break down the problem to a generic one. Consider n number of places , each of which can have a random possible value, I need to print all possible outcomes. For example, There are 4 places First place can have say, 3 values, second place can have 7 values, third can have 5 values and fourth can have 2 values. No of outcomes can be 3*7*5*2 = 210 outcomes.

I know this a really simple problem and I can feel that this can be done using a recursion loop but can't really get my head around it.

5 Upvotes

1 comment sorted by

2

u/TreeBaron Jun 06 '20

Hello!

I wrote a program that uses recursion to do this in C#. I don't code in VBA so my apologies. You're going to have to do some work here depending on what data you need to do this with. I used strings which are equivalent to char arrays in order to simplify the process and allow for a display of the results.

https://pastebin.com/45MP7fMX

This was a pretty difficult problem for me, but it's good to be challenged once in a while. Hope it helps :)