I have two lists, say val l1 = List(1, 2, 3, 4) and val l2 = List(5, 6, 7, 8) and I'd like to merge and shuffle them in a manner that items ordering in the scope of the individual list remain the same, but result list is shuffled.
Let me, please, explain and show a couple of examples:
Desired - List(1, 2, 5, 6, 3, 4, 7, 8) - as you may see original items order from l1 preserved - after 1 goes 2, after 2, goes 3 - skipping items from l2, because we look at the elements from l1 relatively to each other only. And same for l2 after 5 goes 6 and so on.
Desired - List(5, 6, 1, 2, 7, 8, 3, 4) - elements order from l1 and l2 preserved relatevly to each other, similarly to previous example.
Wrong - List(6, 5, 1, 2, 7, 8, 3, 4) - 6 goes before 5, which was not like in l2.
So simple Random.shuffle(l1 ++ l2) won't work for me.
Assume all items in both lists are unique.
Is there any elegant way to do this? Thank you!