I am fairly new at programming in C and I'm having problems with writing a program which combines n objects from n different groups and prints them; for example objects a1 a2 a3from group A with b1 b2 b3 from group B and c1 c2 from group C; both group number and objects number may vary; the final possible combinations must contain 1 object from each group at the time (for example a1 b3 c2 is ok, but a1 a2 b3 is wrong because there are two objects from the same group and none from the third group). So far I've made several attempts using lists, rb trees, etc but I don't seem to be getting anywhere. So I'd really appreciate some help.... Thanks
SanJuanWolf
0
Newbie Poster
Recommended Answers
Jump to PostThink of it like three wheels on an old fashioned car odometer. Each wheel is from a different group, and each wheel can spin around, and then go back to it's starting value.
Three nested for loops is the simplest implementation I know. Arrays are what I use, for …
Jump to PostThat's not a logical problem - think of your odometer wheels again. Imagine that instead of each wheel having 10 digits (0-9), that the right most wheel of the three (which is the one I use as the "driver" wheel), has only two digits, 1 and 2. And the middle …
Jump to PostThe data type is irrelevant. You can do what I suggested with any data type. It's a matter of logic.
1) You can't have s[1] = 1, 2, 8, etc. s[1] is the element in s[] right next to s[0] and s[2], and can hold just one integer, not …
Jump to Post@SanJuanWolf
Who decided the number of groups ?@Adak
Quick question. How do you plan to implement nested loops when the number of groups is a variableI have a dirty solution which may work in this scenario but I am hoping Adak can make that unnecessary
Jump to PostWhatever the constraints are, they'll have to have logic to handle it. Nothing magical about nested for loops, they're just a good simple way, to handle creating combinations.
The more difficult the problem, the more likely the logic will need to move to a more representative design, and at …
All 19 Replies
Adak
419
Nearly a Posting Virtuoso
SanJuanWolf
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
SanJuanWolf
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
SanJuanWolf
0
Newbie Poster
abhimanipal
91
Master Poster
Adak
419
Nearly a Posting Virtuoso
SanJuanWolf
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
abhimanipal
91
Master Poster
SanJuanWolf
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
Adak
419
Nearly a Posting Virtuoso
SanJuanWolf
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
Adak
419
Nearly a Posting Virtuoso
rishabhsetia65
0
Newbie Poster
Airshow
416
WiFi Lounge Lizard
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.