Skip to main content
added 86 characters in body
Source Link
user
  • 457
  • 2
  • 21
  • 71

Scala, 114 109109 119 bytes

+10 bytes to fix a mistake, indirectly pointed out by AZTECCO.

n=>for(k<-Stream from 2;s=Seq.iterate(k,n+1)(x=>1.to(x-1).filter(x%_<1).sum).tail.distinct if s.indexOf(k)>n-2)yield s 

Try it in Scastie!Try it in Scastie!

An infinite Stream that can also be treated as a function that returns the mth sequence. Uses tail instead of init like the previous one, so the sequences are [284, 220], [220, 284], [1210, 1184] (first element removed).

Using >n-2, as in Arnauld's answer, instead of ==n-1, saves a byte.

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 ).tail //Drop the first element (always k) if s.indexOf(k) > n - 2 //Make sure k appears at the end of the cycle (and only there) ) yield s //Yield the sequence (without k at the start) 

Scala, 114 109 bytes

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-2)yield s 

Try it in Scastie!

An infinite Stream that can also be treated as a function that returns the mth sequence. Uses tail instead of init like the previous one, so the sequences are [284, 220], [220, 284], [1210, 1184] (first element removed).

Using >n-2, as in Arnauld's answer, instead of ==n-1, saves a byte.

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 ).tail //Drop the first element (always k) if s.indexOf(k) > n - 2 //Make sure k appears at the end of the cycle (and only there) ) yield s //Yield the sequence (without k at the start) 

Scala, 114 109 119 bytes

+10 bytes to fix a mistake, indirectly pointed out by AZTECCO.

n=>for(k<-Stream from 2;s=Seq.iterate(k,n+1)(x=>1.to(x-1).filter(x%_<1).sum).tail.distinct if s.indexOf(k)>n-2)yield s 

Try it in Scastie!

An infinite Stream that can also be treated as a function that returns the mth sequence. Uses tail instead of init like the previous one, so the sequences are [284, 220], [220, 284], [1210, 1184] (first element removed).

Using >n-2, as in Arnauld's answer, instead of ==n-1, saves a byte.

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 ).tail //Drop the first element (always k) if s.indexOf(k) > n - 2 //Make sure k appears at the end of the cycle (and only there) ) yield s //Yield the sequence (without k at the start) 
deleted 154 characters in body
Source Link
user
  • 457
  • 2
  • 21
  • 71

Scala, 114114 109 bytes

n=>for(k<-Stream from 2;s=Seq.iterate(k,n+1)(x=>1.to(x-1).filter(x%_<1).sum).tail if s.tail.indexOf(k)==n>n-12)yield s.init 

Try it in Scastie!

An infinite Stream that can also be treated as a function that returns the mth sequence. Uses tail instead of init like the previous one, so the sequences are [284, 220], [220, 284], [1210, 1184] (first element removed).

Using >n-2, as in Arnauld's answer, instead of ==n-1, saves a byte.

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 ).tail  //SumDrop them the first element (always k) if s.tail.indexOf(k) ==> n - 12  //Make sure k appears at the end of the cycle (and only there) ) yield s.init  //Yield all but the last elementsequence (which iswithout k) 

Possible 110 byte solution

n=>for(k<-Stream from 2;s=Seq.iterate(k,n+1)(x=>1.to(x-1).filter(x%_<1).sum).tailat ifthe s.indexOf(k)==n-1start)yield s 

Try it online1

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.

Scala, 114 bytes

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!

An infinite Stream that can also be treated as a function that returns the mth sequence.

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

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

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.

Scala, 114 109 bytes

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-2)yield s 

Try it in Scastie!

An infinite Stream that can also be treated as a function that returns the mth sequence. Uses tail instead of init like the previous one, so the sequences are [284, 220], [220, 284], [1210, 1184] (first element removed).

Using >n-2, as in Arnauld's answer, instead of ==n-1, saves a byte.

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 ).tail  //Drop the first element (always k) if s.indexOf(k) > n - 2  //Make sure k appears at the end of the cycle (and only there) ) yield s  //Yield the sequence (without k at the start) 
Source Link
user
  • 457
  • 2
  • 21
  • 71

Scala, 114 bytes

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!

An infinite Stream that can also be treated as a function that returns the mth sequence.

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

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

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.