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 Revisions

2 of 4
added a commented version
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 80 bytes

Expects a string.

f=(n,m=n,k=2)=>k>n?1:n%k?f(n,m,k+1):m-k&&m.match([...k+''].join`.*`)&&f(n/k,m,k)

Try it online!

Commented

f = ( // f is a recursive function taking:
 n, // n = initially the input as a string,
 // then an integer
 m = n, // m = copy of the input
 k = 2 // k = current divisor
) => //
 k > n ? // if k is greater than n:
 1 // stop the recursion
 : // else:
 n % k ? // if k is not a divisor of n:
 f(n, m, k + 1) // recursive call with k + 1
 : // else:
 m - k && // if k is not equal to m
 m.match( // and the digits of k can be found in
 [...k + ''].join`.*` // the correct order in m:
 ) && //
 f(n / k, m, k) // do a recursive call with n / k
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

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