Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

saved 1 byte / added another version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (V8) , 76 bytes

Prints the sequence indefinitely.

for(k=9;++k;)(g=x=>x>1?g(x%d++?x:x/--d):k+g)(k-1,d=2).match(d+"x")&&print(k)

Try it online!


JavaScript (ES6), 8079 bytes

f=(n,k)=>!(g=x=>x>1?g(x%d++?x:x/--d):k+""k+g)(k-1,d=2).match(d+"$"d+"x")||n--?f(n,-~k):k

Try it online! Try it online!

f = ( // f is a recursive function taking:
 n, // n = input
 k // k = counter, initially undefined
) => //
!( //
 g = x => // g is a recursive function taking x:
 x > 1 ? // if x is greater than 1:
 g( // do a recursive call to g:
 x % d++ ? // if d is not a divisor of x
 // (increment d afterwards):
 x // leave x unchanged
 : // else:
 x / --d // restore d and divide x by d
 ) // end of recursive call
 : // else:
 k + ""g  // return k, converted to a string with
) // a suffix starting with "x"
(k - 1, d = 2) // initial call to g with k - 1 and d = 2
.match(d + "$""x") // if d is not a suffix of k
|| n-- ? // or n is not 0 (decrement it afterwards):
 f(n, -~k) // try again with k + 1
: // else:
 k // stop and return k

JavaScript (ES6), 80 bytes

f=(n,k)=>!(g=x=>x>1?g(x%d++?x:x/--d):k+"")(k-1,d=2).match(d+"$")||n--?f(n,-~k):k

Try it online!

f = ( // f is a recursive function taking:
 n, // n = input
 k // k = counter, initially undefined
) => //
!( //
 g = x => // g is a recursive function taking x:
 x > 1 ? // if x is greater than 1:
 g( // do a recursive call to g:
 x % d++ ? // if d is not a divisor of x
 // (increment d afterwards):
 x // leave x unchanged
 : // else:
 x / --d // restore d and divide x by d
 ) // end of recursive call
 : // else:
 k + "" // return k, converted to a string
) //
(k - 1, d = 2) // initial call to g with k - 1 and d = 2
.match(d + "$") // if d is not a suffix of k
|| n-- ? // or n is not 0 (decrement it afterwards):
 f(n, -~k) // try again with k + 1
: // else:
 k // stop and return k

JavaScript (V8) , 76 bytes

Prints the sequence indefinitely.

for(k=9;++k;)(g=x=>x>1?g(x%d++?x:x/--d):k+g)(k-1,d=2).match(d+"x")&&print(k)

Try it online!


JavaScript (ES6), 79 bytes

f=(n,k)=>!(g=x=>x>1?g(x%d++?x:x/--d):k+g)(k-1,d=2).match(d+"x")||n--?f(n,-~k):k

Try it online!

f = ( // f is a recursive function taking:
 n, // n = input
 k // k = counter, initially undefined
) => //
!( //
 g = x => // g is a recursive function taking x:
 x > 1 ? // if x is greater than 1:
 g( // do a recursive call to g:
 x % d++ ? // if d is not a divisor of x
 // (increment d afterwards):
 x // leave x unchanged
 : // else:
 x / --d // restore d and divide x by d
 ) // end of recursive call
 : // else:
 k + g  // return k, converted to a string with
) // a suffix starting with "x"
(k - 1, d = 2) // initial call to g with k - 1 and d = 2
.match(d + "x") // if d is not a suffix of k
|| n-- ? // or n is not 0 (decrement it afterwards):
 f(n, -~k) // try again with k + 1
: // else:
 k // stop and return k
added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

Commented

f = ( // f is a recursive function taking:
 n, // n = input
 k // k = counter, initially undefined
) => //
!( //
 g = x => // g is a recursive function taking x:
 x > 1 ? // if x is greater than 1:
 g( // do a recursive call to g:
 x % d++ ? // if d is not a divisor of x
 // (increment d afterwards):
 x // leave x unchanged
 : // else:
 x / --d // restore d and divide x by d
 ) // end of recursive call
 : // else:
 k + "" // return k, converted to a string
) //
(k - 1, d = 2) // initial call to g with k - 1 and d = 2
.match(d + "$") // if d is not a suffix of k
|| n-- ? // or n is not 0 (decrement it afterwards):
 f(n, -~k) // try again with k + 1
: // else:
 k // stop and return k

Commented

f = ( // f is a recursive function taking:
 n, // n = input
 k // k = counter, initially undefined
) => //
!( //
 g = x => // g is a recursive function taking x:
 x > 1 ? // if x is greater than 1:
 g( // do a recursive call to g:
 x % d++ ? // if d is not a divisor of x
 // (increment d afterwards):
 x // leave x unchanged
 : // else:
 x / --d // restore d and divide x by d
 ) // end of recursive call
 : // else:
 k + "" // return k, converted to a string
) //
(k - 1, d = 2) // initial call to g with k - 1 and d = 2
.match(d + "$") // if d is not a suffix of k
|| n-- ? // or n is not 0 (decrement it afterwards):
 f(n, -~k) // try again with k + 1
: // else:
 k // stop and return k
saved 3 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 8380 bytes

Returns the \$n\$-th term of the sequence, 1-indexed.

f=(i,n,k)=>!(n+"").match((g=n=>k<=ng=x=>x>1?g(n%k++x%d++?nx:nx/--kd):k+"$"k+"")(nk-1,k=2d=2).match(d+"$")||i||n--?f(in,-~n~k):nk

Try it online! Try it online!

JavaScript (ES6), 83 bytes

Returns the \$n\$-th term of the sequence, 1-indexed.

f=(i,n)=>!(n+"").match((g=n=>k<=n?g(n%k++?n:n/--k):k+"$")(n-1,k=2))||i--?f(i,-~n):n

Try it online!

JavaScript (ES6), 80 bytes

Returns the \$n\$-th term of the sequence, 1-indexed.

f=(n,k)=>!(g=x=>x>1?g(x%d++?x:x/--d):k+"")(k-1,d=2).match(d+"$")||n--?f(n,-~k):k

Try it online!

saved 4 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

AltStyle によって変換されたページ (->オリジナル) /