Skip to main content
added 47 characters in body
Source Link
histocrat
  • 22.3k
  • 4
  • 39
  • 81

Ruby 2.6, 51 bytes

f=->s,n{[s,l=(2..).find{|d|~s%d<1}][n]||f[l*s,n-1]} 

(2..), the infinite range starting from 2, isn't supported on TIO yet.

This is a recursive function that takes a starting value s (can be a prime or composite), returns it when n=0 (edit: note that this means it's zero-indexed), returns the least number l that's greater than 1 and divides -(s+1) when n=1, and otherwise recurses with s=l*s and n=n-1.

Ruby 2.6, 51 bytes

f=->s,n{[s,l=(2..).find{|d|~s%d<1}][n]||f[l*s,n-1]} 

(2..), the infinite range starting from 2, isn't supported on TIO yet.

This is a recursive function that takes a starting value s (can be a prime or composite), returns it when n=0, returns the least number l that's greater than 1 and divides -(s+1) when n=1, and otherwise recurses with s=l*s and n=n-1.

Ruby 2.6, 51 bytes

f=->s,n{[s,l=(2..).find{|d|~s%d<1}][n]||f[l*s,n-1]} 

(2..), the infinite range starting from 2, isn't supported on TIO yet.

This is a recursive function that takes a starting value s (can be a prime or composite), returns it when n=0 (edit: note that this means it's zero-indexed), returns the least number l that's greater than 1 and divides -(s+1) when n=1, and otherwise recurses with s=l*s and n=n-1.

Source Link
histocrat
  • 22.3k
  • 4
  • 39
  • 81

Ruby 2.6, 51 bytes

f=->s,n{[s,l=(2..).find{|d|~s%d<1}][n]||f[l*s,n-1]} 

(2..), the infinite range starting from 2, isn't supported on TIO yet.

This is a recursive function that takes a starting value s (can be a prime or composite), returns it when n=0, returns the least number l that's greater than 1 and divides -(s+1) when n=1, and otherwise recurses with s=l*s and n=n-1.