I would recommend that you avoid too many nested conditions and loops. And is there a reason why you want your answer to involve a list comprehension? I like using them too, but beyond a point they become too long to, um... comprehend. Here's an alternative solution that uses fewer loops, avoids long list comprehensions and is easier to read -- to my eyes, at least. In [29]: from itertools import permutations, combinations_with_replacement In [30]: def all_valid_permutations(candies, members): ...: combos = combinations_with_replacement(range(1, candies), members) ...: valid_permutations = set() ...: for item in combos: ...: for perm in permutations(item): ...: if sum(perm) == candies and len(set(perm)) >= members-1: ...: valid_permutations.add(perm) ...: ...: return valid_permutations ...: In [31]: all_valid_permutations(6, 3) Out[31]: {(1, 1, 4), (1, 2, 3), (1, 3, 2), (1, 4, 1), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1), (4, 1, 1)}If you know your basic combinatorics you can guess what the imported functions do. (Or you can read the docs, if you prefer.) I can't guarantee performance, though, without fully knowing your use-case. This is just a quick solution, off the top of my head. I bet you can optimise this further. Uh-Oh! That’s all you get for now. We would love to personalise your learning journey. Sign Up to explore more. Sign Up or Login Skip for now Uh-Oh! That’s all you get for now. We would love to personalise your learning journey. Sign Up to explore more. Sign Up or Login Skip for now
$\begingroup$
Number of ways of distributing $6$ chocolates among $3$ children so that each child gets at least one of them Now, question doesn't mentions whether chocolates are distinct or identical(children distinct of course) Case 1: Chocolates identical: so we're looking for number of positive integral solutions to the equation : $x_1 + x_2 + x_3 = 6$ which is $C(5,2) = 10$ Case 2: Chocolates distinct: here we're looking for onto function from a set $A$ of cardinality $6$ to set $B$ of cardinality $3$ = $S(6,3)$ $S$ is Stirling number of 2nd Kind. Is this correct?
$\endgroup$ 1
GMAT Club Legend Joined: 08 Jul 2010 Status:GMAT/GRE Tutor l Admission Consultant l On-Demand Course creator Posts: 5920 Location: India GMAT: QUANT EXPERT Schools: IIM (A), ISB WE:Education (Education)
In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 16 May 2017, 06:52
00:00
Difficulty: 75% (hard)
Question Stats: 51% (01:29) correct 49% (01:58) wrong based on 248 sessionsHide Show timer StatisticsIn how many ways can 6 chocolates be distributed among 3 children? A child may get any number of chocolates from 1 to 6 and all the chocolates are identical.A) 10B) 15C) 21D) 28E) 56 SOURCE: http://www.GMATinsight.com _________________
GMATinsight SUCCESS STORIES: From 620 to 760 l Q-42 to Q-49 in 40 days l 590 to 710 + Wharton l GMAT730+ESCP FREE Resources: 22 FULL LENGTH TESTS l OG QUANT 50 Qn+VIDEO Sol. l NEW:QUANT REVISION Topicwise Quiz
Retired Moderator Joined: 21 Aug 2013 Posts: 1270 Location: India
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 26 Apr 2018, 10:23
Awamy wrote: why the formula of identical objects doen'st work here ? So in this question, since 6 identical chocolates have to be distributed among 3 distinct people, but everyone should get at least one, we will apply the second formula = (6-1) C (3-1) = 5C2 = 10, which is our answer
Senior Manager Joined: 13 Oct 2016 Posts: 318 GPA: 3.98
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 16 May 2017, 07:18
GMATinsight wrote: In how many ways can 6 chocolates be distributed among 3 children? A child may get any number of chocolates from 1 to 6 and all the chocolates are identical.A) 10B) 15C) 21D) 28E) 56 SOURCE: http://www.GMATinsight.com Hi# of chocolates distributed to each child -\(x_1, x_2, x_3\), where \(x_i > 0\)We have non-empty set:\(x_1 + x_2 + x_3 = 6\)We need to convert it into \(x_i >=0\) substituting each \(x_i\) with \(y_i = x_i - 1\). \(x_i = y_i +1\):\(y_1 + y_2 + y_3 = 3\)\(_{3+3-1}C_3 = _5C_3 = \frac{5*4}{2} = 10\)Answer A
Manager Joined: 24 Mar 2015 Status:love the club... Posts: 227
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 09 Jan 2018, 10:19
GMATinsight wrote: In how many ways can 6 chocolates be distributed among 3 children? A child may get any number of chocolates from 1 to 6 and all the chocolates are identical.A) 10B) 15C) 21D) 28E) 56 SOURCE: http://www.GMATinsight.com \\since a child must get at least 1 chocolate, lets distribute 1 chocolate to each child first, and thus we are left with 3 chocolates to redistribute now we are in businesssince chocolates are identical, the remaining 3 chocolates can be distributed among 3 children as follows 5!_____3! 2!= 10, the answer hope this helpsthankscheers, and do consider some kudos, guys
Intern Joined: 20 Nov 2017 Posts: 4
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 26 Apr 2018, 08:02 why the formula of identical objects doen'st work here ?
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 17 Dec 2018, 05:21 chetan2u Bunuel could you please explain how to solve this without (n-1)Cr-1 ... i wanna learn the concept
GMAT Club Legend Joined: 18 Aug 2017 Status:You learn more from failure than from success. Posts: 7285 Location: India Concentration: Sustainability, Marketing GPA: 4 WE:Marketing (Energy and Utilities)
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 28 Jul 2019, 01:58
GMATinsight wrote: In how many ways can 6 chocolates be distributed among 3 children? A child may get any number of chocolates from 1 to 6 and all the chocolates are identical.A) 10B) 15C) 21D) 28E) 56 SOURCE: http://www.GMATinsight.com formula to use here we can take case that child may get 0 chocolate n-1Cr-1 ; n=6 . r= 3 5c2; 10IMO A
SVP Joined: 24 Nov 2016 Posts: 1806 Location: United States
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 26 Aug 2019, 13:02
GMATinsight wrote: In how many ways can 6 chocolates be distributed among 3 children? A child may get any number of chocolates from 1 to 6 and all the chocolates are identical.A) 10B) 15C) 21D) 28E) 56 SOURCE: http://www.GMATinsight.com given: 6 identical chocs, 3 different kids, at least 1 each;\(k_1+k_2+k_3=6…(k_1'+1)+(k_2+1)+(k_3+1)=6…k_1'+k_2+k_3=3\)\(C(n+r-1,r-1)=(3+3-1,3-1)=\frac{5!}{2!3!}=10\)Answer (A)
GMAT Club Legend Joined: 08 Jul 2010 Status:GMAT/GRE Tutor l Admission Consultant l On-Demand Course creator Posts: 5920 Location: India GMAT: QUANT EXPERT Schools: IIM (A), ISB WE:Education (Education)
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 28 Feb 2020, 23:10
GMATinsight wrote: In how many ways can 6 chocolates be distributed among 3 children? A child may get any number of chocolates from 1 to 6 and all the chocolates are identical.A) 10B) 15C) 21D) 28E) 56 SOURCE: http://www.GMATinsight.com The detailed solution to the above problem using two methods is explained in the attached video _________________
GMATinsight SUCCESS STORIES: From 620 to 760 l Q-42 to Q-49 in 40 days l 590 to 710 + Wharton l GMAT730+ESCP FREE Resources: 22 FULL LENGTH TESTS l OG QUANT 50 Qn+VIDEO Sol. l NEW:QUANT REVISION Topicwise Quiz
Target Test Prep Representative Joined: 14 Oct 2015 Status:Founder & CEO Affiliations: Target Test Prep Posts: 16477 Location: United States (CA)
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 17 Apr 2020, 10:10
GMATinsight wrote: In how many ways can 6 chocolates be distributed among 3 children? A child may get any number of chocolates from 1 to 6 and all the chocolates are identical.A) 10B) 15C) 21D) 28E) 56 SOURCE: http://www.GMATinsight.com Let the children be A, B, and C. So A can get 1, B can get 1 and C can get 4 chocolates. Of course, this is different from A gets 4, B 1, and C 1, or, A gets 1, B 4, and C 1. In the calculations below, we will show how 3 positive integers can sum to 6 and the number of ways the 3 numbers can be rearranged among A, B, and C (for example, the first calculation below describes the distribution of the 6 chocolates mentioned above): 1 + 1 + 4 = 63!/2! = 3 ways1 + 2 + 3 = 6 3! = 6 ways2 + 2 + 2 = 63!/3! = 1 wayTherefore, there are a total of 3 + 6 + 1 = 10 ways that 6 chocolates can be distributed to 3 children._________________
Non-Human User Joined: 09 Sep 2013 Posts: 25079
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 22 Jan 2022, 09:50 Hello from the GMAT Club BumpBot!Thanks to another GMAT Club member, I have just discovered this valuable topic, yet it had no discussion for over a year. I am now bumping it up - doing my job. I think you may find it valuable (esp those replies with Kudos).Want to see all other topics I dig out? Follow me (click follow button on profile). You will receive a summary of all topics I bump in your profile area as well as via email. _________________
Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink] 22 Jan 2022, 09:50 |