+ 42

[ASSIGNMENT] 👉👉👉 ENVELOPE 📧 & LETTER 💌

U have to find number of ways in which no letter goes to correct envelope example ::: if input is 3 then , 3 envelope E1,E2,E3 3 letters L1,L2,L3 //correct combination ::: (E1L1 , E2L2 , E3L3) 👉 possible arrangements (E1L2 , E2L3 , E3L1) (E1L3 , E2L1 , E3L2) /*therefore 2 such combinations for 3 letters and 3 envelopes such that no letter goes in correct envelope*/ //output must be 2 Bonus ::: print the combinations 🙌 all languages are welcome ☺ //best of luck & happy coding ☺👍

10th Feb 2018, 1:05 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
24 Answers
+ 25
no@J.G. I mean none of the letter goes to correct envelope , so there are some combinations which u need to exclude /*even if 1 letter goes to correct envelope , then u have to remove that combination*/ //thats interesting ... right ? ☺
10th Feb 2018, 1:14 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 19
this whole is 1st combination ::: (E1L2 , E2L3 , E3L1) this whole is 2nd comvination ::: (E1L3 , E2L1 , E3L2) //so 2 combinations //read the description carefully ☺ & try again 👍👍👍👍 /*I'll tell mathematical answer soon*/
10th Feb 2018, 3:36 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 18
here is some brief explanation on it input : 3 //3 letters , 3 envelopes output : 2 //how output comes as 2 , for what combinations ? 👇 1) total no. of combinations we can make is 3! = 6 (ie no. of ways of 3 letters in 3 envelope .... {1 letter in 1 envelope , u can't put 2 or more letters in 1 envelope} ) envelopes are E1,E2,E3 ... letters are L1,L2,L3 E1 is correct envelope for letter L1 , similarily ... E2 for L2 & E3 for L3 now we have to find no. of ways in which all letters are putted into envelopes but none of those letters goes in correct envelopes ... ie L1 doesn't go into E1 , L2 doesn't goes into E2 & L3 doesn't goes into E3 a) (E1L2 , E2L3 , E3L1) b) (E1L3 , E2L1 , E3L2) //2 combination possible ... ie a) and b) as U can see in a) that E1 holds L2 ... not L1 , E2 holds L3 ... not L2 E3 holds L1 ... not L3 //will mark best answer soon , after some more answers ☺👍 INPUT ::::: 3 OUTPUT :::: 2 (E1L2 , E2L3 , E3L1) (E1L3 , E2L1 , E3L2)
10th Feb 2018, 3:00 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 18
upto now , correct answers are of ::: Danigamy , Cpasgrave , DT , Pedro Demingos , Vadim Sukhotin , swim , Chloe //U can check out their codes and understand what to output ☺
11th Feb 2018, 6:23 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 17
thats incorrect /*see the correct codes & compare what should be the output for what input*/
11th Feb 2018, 7:15 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 17
mathematical soln let u have n letters & U have to put them into n envelopes such that 1 letter goes into 1 envelope , then no. of ways such that none of the letter goes to right envelope , then U must substract those ways in which letter(s) goes to correct envelope ie n! - {nC1.(n-1)! - nC2. (n-2)! + nC3. (n-3)! - ..... +(-1)^n.nCn.0!} =n! (1/2! - 1/3! + 1/4! +.....+((-1)^n)/n!) //hope u got it @Sreejith
11th Feb 2018, 9:48 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
10th Feb 2018, 5:22 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 10
So, what you're saying is: If the user inputs x, the output should be every combination except {L1E1, L2E2, ... LXEX}?
10th Feb 2018, 1:09 PM
J.G.
J.G. - avatar
+ 8
A little too long, but there it goes: https://code.sololearn.com/cjq5z97Ua6hU/#py
10th Feb 2018, 6:34 PM
Pedro Demingos
Pedro Demingos - avatar
+ 8
12th Feb 2018, 4:14 PM
Tob
Tob - avatar
10th Feb 2018, 3:33 PM
Yash✳️
Yash✳️ - avatar
12th Feb 2018, 6:08 PM
Tob
Tob - avatar
10th Feb 2018, 5:06 PM
Danigamy
Danigamy - avatar
+ 4
Here's my try: edit: following the rules and corrected name, working on grouping https://code.sololearn.com/cWE9s1StLzk0/?ref=app
10th Feb 2018, 2:36 PM
‎ ‏‏‎Anonymous Guy
+ 4
My lazy brute force python: https://code.sololearn.com/cP85OqQCXBRA/#py 1 letter and 1 envelope - 0 possible ways to completely fail the mailing 2 letters and 2 envelopes - 1 possible way to completely fail the mailing 3 l&e - 2 p 4 l&e - 9 p 5 l&e - 44 p 6 l&e - 265 p 7 l&e - 1854 p 8 l&e - 14833 p 9 l&e - 133496 p
10th Feb 2018, 5:12 PM
Cépagrave
Cépagrave - avatar
+ 4
https://code.sololearn.com/cPxFf4mZS6QJ/?ref=app I get the same as the sample, but in 3 groups of 2; does this make my results incorrect?
10th Feb 2018, 11:14 PM
SQrL
SQrL - avatar
+ 4
I have better results and can match the sample. My solution is incomplete for n>3. https://code.sololearn.com/cmWFNQm6mXoR/?ref=app
12th Feb 2018, 8:58 AM
SQrL
SQrL - avatar
10th Feb 2018, 4:11 PM
‎ ‏‏‎Anonymous Guy
+ 2
and please explain 5=44 factorial of 5(n) is 120 square of n is 25 factorial of n-1 is 24 square of n-1 is 16 n*(n-1) is 20 square of n*(n-1) is 400 even if you do this 120-25-24-16-5(same combination ) = 50 i can't get it a bit explanation would be good
11th Feb 2018, 8:39 AM
‎ ‏‏‎Anonymous Guy
11th Feb 2018, 10:08 AM
Вадим Сухотин (Vadim Sukhotin)
Вадим Сухотин (Vadim Sukhotin) - avatar