-1
You have N lists
A = [5, 6, 10, 15]
B = [3, 0, 7, 4]
C = [49, 59, 29]
D = [19, 29, 39]
E = [9, 15, 3, 10]
You have to combine them such that: Two lists which have a common elements they should be next to each other. In this case answer is:
A,E,B,C,D
[5, 6, 10, 15, 9, 3, 0, 7, 4, 49, 59, 29, 19, 39]
E comes after A as they have 2 common elements. After E the B comes as they have common elements. B do not have common elements with C or D so anything can come (C or D), lets say C comes. Now C should be followed by D as they have common elements.
Note: This is also acceptable solution
B,E,A,C,D
C,D,A,E,B
....
Thus the main condition is if two lists have common elements they should be next to each other.
Note 2: For simplicity we assume a list can have common elements with maximum 2 other lists. However there can be list which have no common elements with any other list.
Note 3: Output format : preferably both, the name of list and the number sequence.
1What exactly are the input and output formats? Is the output
A,E,B,C,D
or the list of numbers? is it always a single letter identifier before the equals? Please clarify. – isaacg – 2015-08-11T09:45:06.363@isaacg output format can be A,E,B,C,D . Does the identifier of list matter !! If so yes it can be more then one letter – d.putto – 2015-08-11T11:23:48.510
Sometimes this is not possible. What to do then? – proud haskeller – 2015-08-11T15:36:56.547
I think you'll have to specify if the number sequence is required or not. Or give a bonus for outputting the number sequence. For a code golf contest, "preferably" is too vague. Also, if the number sequence is involved, I don't see a clear definition of what it is. I think I understand it based on the example (common elements are only listed once, between the two lists?), but a more formal definition would be useful. But if it's purely optional, you might just as well remove it completely. – Reto Koradi – 2015-08-11T15:37:59.040