How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

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

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

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)

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  16 May 2017, 06:52

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

00:00

Difficulty:

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
75% (hard)

Question Stats:

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
51% (01:29) correct
How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
49% (01:58) wrong
How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
based on 248 sessions

Hide Show timer Statistics

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

_________________

GMATinsight
Great Results (Q≥50 and V≥40) l Honest and Effective Admission Support l 100% Satisfaction !!!
One-on-One GMAT Skype classes l On-demand Quant Courses and Pricing l Admissions ConsultingCall/mail: +91-9999687183 l (for FREE Demo class/consultation)

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]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  26 Apr 2018, 10:23

Awamy wrote:

why the formula of identical objects doen'st work here ?
Is there any easy way to solve such problems please ?

Hello The formula of identical objects DOES work here. If we have to distribute N identical objects among R distinct groups such that one or more people might get none of the objects, then the formula is = (N+R-1) C (R-1) (selecting R-1 objects out of N+R-1 objects)BUT if N identical objects have to be distributed among R distinct groups such that everyone should get at least one object, then the formula is = (N-1) C (R-1) (selecting R-1 objects out of N-1 objects)

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

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

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]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

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]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

Intern

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

Joined: 20 Nov 2017

Posts: 4

Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  26 Apr 2018, 08:02

why the formula of identical objects doen'st work here ?
Is there any easy way to solve such problems please ?

Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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)

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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; 10

IMO 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]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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
Great Results (Q≥50 and V≥40) l Honest and Effective Admission Support l 100% Satisfaction !!!
One-on-One GMAT Skype classes l On-demand Quant Courses and Pricing l Admissions ConsultingCall/mail: +91-9999687183 l (for FREE Demo class/consultation)

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]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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._________________

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

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]

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?
  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. _________________

How many ways can 6 Chocolates be distributed among 3 children a child may get any number of chocolates from 0 to 6 and all the chocolates are identical?

Re: In how many ways can 6 chocolates be distributed among 3 children? A c [#permalink]