1

In scala, I am trying to sort the below sequence of sequence,

Seq(Seq(2,3,4),Seq(1),Seq(1,2),Seq(1,2),Seq(1,2,3),Seq(2,3),Seq(1,3,4),
  Seq(2,3,4,5),Seq(2,3,5),Seq(3,4,6),Seq(3,4),Seq(3,4,5))
.sortWith((a,b)=>{
  (a zip b).filterNot(x => (x._1==x._2 || x._1 &gt x._2)).size > b.size
})

Output required:

  <br/>1
  <br/>1, 2
  <br/>1, 2
  <br/>1, 2, 3
  <br/>1, 3, 4
  <br/>2, 3
  <br/>2, 3, 4
  <br/>2, 3, 4, 5
  <br/>2, 3, 5
  <br/>3,4
  <br/>3,4,5
  <br/>3,4,6


The pattern that I am looking for is similar to the following,

  <br/>1
  <br/>1,2
  <br/>1,2,3
  <br/>1,3,4
  <br/>2,4
  <br/>2,4,5
  <br/>2,5,6,7
  <br/>3
  <br/>3,4
  <br/>3,4,5
This pattern is similar to triangle but should start with the same number and then again another triangle which should start next to the previous starting number.

It is straight forward to compare 2 sequences but this is challenging.

Please help me resolve the scenario.

0 Answers0