# Scala, 114 bytes ```scala n=>for(k<-Stream from 2;s=Seq.iterate(k,n+1)(x=>1.to(x-1).filter(x%_<1).sum)if s.tail.indexOf(k)==n-1)yield s.init ``` [Try it in Scastie!](https://scastie.scala-lang.org/5lW7J5kgRM624Lu6tx4ofw) An infinite `Stream` that can also be treated as a function that returns the mth sequence. ```scala n => for( k <- Stream from 2 //For every integer k ≥ 2 s = Seq.iterate(k, n + 1)( //Build first n+1 terms of the sequence by repeatedly applying: x => //Function for proper divisor sum 1.to(x - 1) //Range of possible proper divisors .filter(x % _ < 1) //Keep only divisors .sum //Sum them ) if s.tail.indexOf(k) == n - 1 //Make sure k appears at the end of the cycle (and only there) ) yield s.init //Yield all but the last element (which is k) ``` ### Possible 110 byte solution ```scala n=>for(k<-Stream from 2;s=Seq.iterate(k,n+1)(x=>1.to(x-1).filter(x%_<1).sum).tail if s.indexOf(k)==n-1)yield s ``` [Try it online1](https://scastie.scala-lang.org/Z3RzysDURSmRIiH3sBAvzw) Uses `tail` instead of `init` like the one above, so the sequences are `[284, 220]`, `[220, 284]`, `[1210, 1184]` (first element removed). Not sure if it's valid, though.