+ 4

[ASSIGNMENT] Assembly line of a Factory

A product consist of elements {A,B,C,D,E,F,G} which come to the worker by assembly line. To prevent mistakes elements must come in complete groups (with no specific order) separated by at least 5 empty places (*) so the worker will be able to assemble the product on time. Elements in each group can be separated by empty places as well, but no more then 4 per group in order to be productive. TASK: Check if the input string (sequence of elements on the assembly line) is valid. Thanks for the idea to @JPM7 !

3rd May 2018, 9:19 AM
Nevfy
46 Answers
+ 4
===== THIS COMMENT PRESENTS ALL ACCEPTED SOLUTIONS. IF YOU ALSO WANT TO SOLVE THIS CHALLENGE PLEASE LOOK FOR MY OTHER COMMENT IN THIS TOPIC TO SEE SOME EXAMPLES AND CLARIFICATION NOTES. ===== More than one week past from the assignment publication and it seems that everyone who wanted to participate have already done it. So, as usual, I sum it up with the list of all accepted solutions: TASK 1 + EXTRA TASK: @Kinshuk Vasisht (C++): https://code.sololearn.com/cIRvuqCCapNu/?ref=app @Edward (Python): https://code.sololearn.com/cU0NZz3n3jji/?ref=app @LukArToDo (kt): https://code.sololearn.com/c7SdKdwdz9CV/?ref=app @Nevfy (Python): https://code.sololearn.com/cIhAYwn0hpG6/?ref=app TASK 1: @VcC (Python): https://code.sololearn.com/cfWHb3IRQ63z/?ref=app
12th May 2018, 12:41 AM
Nevfy
+ 16
https://code.sololearn.com/c76duHs8v8OQ/?ref=app
5th May 2018, 5:34 PM
LukArToDo
LukArToDo - avatar
+ 11
Nevfy Please check if the code is working properly (without super extra task) : https://code.sololearn.com/c7SdKdwdz9CV/?ref=app
20th May 2018, 8:06 AM
LukArToDo
LukArToDo - avatar
+ 4
EXAMPLES: 1. ABCDEFG -> True 2. ABCDEFG**ABCDEFG -> False (distance between sequencies is too short) 3. ABC*DEFG*****AF*CD*EBG -> True 4. A*B*C*D*E*F*G -> False (too much delay between elements in one sequence) 5. ABBBBBB -> False (repeated element for assemblage) 6. AB -> False (not enough elements for assemblage) EXTRA TASK: Print out also how many details can be assembled from a given string. If an input string is False print out anyway how many details can be assembled before the error in line appears. NOTE: I assume that one (not 0) product will be produced from the sequence "ABCDEFG****ABCDEFG", because there are all required details for it but not enough time to finish assemblage before elements for second product start arrive, that makes creation of second product impossible and turns the string to be False. SUPER EXTRA TASK (!) : Find the minimum amount of corrections that should be done in the input string to make it correct. One correction means that you can move an existing element to the neighbor place (if it is empty) or add any element to any empty space or remove any element from the string at all. Good luck! It is really not an easy one!
3rd May 2018, 9:27 AM
Nevfy
3rd May 2018, 10:07 AM
VcC
VcC - avatar
+ 3
Here is my own solution for that challenge: https://code.sololearn.com/cIhAYwn0hpG6/?ref=app I analyze input string element by element and stop it as soon as it becomes wrong. I was trying to comment it well to make it more or less educative and explain logic of decision taken at each step. Feel free to test it and tell me if I've done something wrong. :-) You can also find a test set, which I used to verify your solutions in the end of my code.
12th May 2018, 12:35 AM
Nevfy
+ 2
My Try, excluding the Super Extra Task, for now : https://code.sololearn.com/cIRvuqCCapNu/?ref=app
7th May 2018, 4:00 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Yoohooo ! By doing only one task i have a category for myself.
12th May 2018, 6:58 AM
VcC
VcC - avatar
+ 1
Please use # or * instead of spaces in your example, difficult to read otherwise !
3rd May 2018, 9:51 AM
VcC
VcC - avatar
+ 1
@VcC I have finally found some time to think about a test set. Your solution works well for Main Task unless for one specific case: for input "*" it should return True and 0 pieces (as it does for an empty string). And in fact exactly the same bug causes that your solution returns False for input "ABCDEFG*", however it is True. For Extra Task: you should return number of assembled pieces not only for True string but also for False string. In such case you should print amount of pieces that worker was able to assemble before string became False. I have also add a bit more difficult Super Extra Task, so you can try to solve it as well. However, unfortunately, there are not many participants in this challenge... I would not say that it's too difficult... Maybe I'll publish something even more easy to understand how many person will be attracted...
5th May 2018, 3:57 PM
Nevfy
+ 1
@LukArToDo This is a set of input strings for which your solution returns False, however correct result is True: ("ABCDEFG*","*","")
5th May 2018, 7:12 PM
Nevfy
+ 1
@VcC Accepted for the Main Task! Thanks for participation!
5th May 2018, 8:01 PM
Nevfy
+ 1
Nevfy Shouldn't the third test case be false? As in that case, element G is produced twice in a single group, and as far as I could understand, each group must have unique 7 elements in no set order. So, maybe one of them is an A instead ? If not, please clarify my doubt.
7th May 2018, 2:56 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
@Kinshuk Vasisht Yes, sorry, it definitely should be 'A' there. I have corrected it already. Thanks!
7th May 2018, 4:01 AM
Nevfy
+ 1
@Kinshuk Vasisht Good start, it works for some of test, however it returns string "ABCDEFG******ABCDEFG" to be False, because length of the break between two groups is too big, but there is no such rule in challenge description. It just should be at least 5, there is no upper bound, so this string is correct. Small remark about extra task: you should print out amount of products but not the elements, so for "ABCDEFG" it should be 1 but not 7.
7th May 2018, 7:25 PM
Nevfy
+ 1
Nevfy I have corrected the code to match the task conditions. Kindly review it now. I had a doubt. For the assembly lines 'AF' and 'A*B*C*D*E*F*G', should the program output 0 details processed or something else?
8th May 2018, 3:15 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
@Kinshuk Vasisht Yes, for both these examples the answer is False and number of products is 0.
8th May 2018, 3:18 AM
Nevfy
+ 1
Here my code, trying to simulate the situation in an assembly line, so I read every entry after each other (what the machine delivers me). https://code.sololearn.com/cU0NZz3n3jji/?ref=app
8th May 2018, 7:39 AM
Edward
Edward - avatar
+ 1
@Edward About your solution: 1. There is a tiny bug, which makes sequence "AB**CD**EFG" not valid and thus yields to 0 products production, however the sequence is correct and 1 product will be assembled. 2. I know it is not clear from the description (now I have added a special note about this case), but for the sequence "ABCDEFG****ABCDEFG" I assume that one but not zero product will be produced.
8th May 2018, 9:36 AM
Nevfy
+ 1
@Kinshuk Vasisht With your new version previous bug is no more observed. Good job. For a moment there is another problem caused, probably, by the lack of explanations. Sequence "******ABCDEFG" is valid, because one product can be assembled and precedent '*' have the same meaning as for delay between 2 sequences. In your case you expect that first product's elements must come from the beginning, so you consider these '*' as a delay in a group, that is not correct. P.S. Could you also, please, modify your code to run through all test cases? It will be much easier for me to test it, because I have a prepared set of tests. For a moment I have to modify your code by my own after each your revision. Thanks!
8th May 2018, 10:36 AM
Nevfy