Skip to main content
minor update
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6),  80  79 bytes

Expects a string.

f=(n,m=n,k=2)=>n%k?k>n||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 candidate ) =>  // n % k ?  //  if k is not a divisor of n: k > n ||  //  stop the recursion if k > n f(n, m, k + 1)  //  otherwise: do a recursive call with k + 1 :  //  else: m - k &&  //  if k is not equal to m m.match( // and we can find in m:  [...k + ''] // and the digits of k canin bethe foundcorrect inorder   [...k + ''].join`.*`  // thepossibly correctwith orderother digits in m:between ) &&  // //then: f(n / k, m, k)  //  do a recursive call with n / k 

JavaScript (ES6),  80  79 bytes

Expects a string.

f=(n,m=n,k=2)=>n%k?k>n||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 ) =>  // n % k ?  //  if k is not a divisor of n: k > n ||  //  stop the recursion if k > n f(n, m, k + 1)  //  otherwise: 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 

JavaScript (ES6),  80  79 bytes

Expects a string.

f=(n,m=n,k=2)=>n%k?k>n||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 candidate ) => // n % k ? // if k is not a divisor of n: k > n || // stop the recursion if k > n f(n, m, k + 1) // otherwise: do a recursive call with k + 1 : // else: m - k && // if k is not equal to m m.match( // and we can find in m:  [...k + ''] // the digits of k in the correct order .join`.*`  // possibly with other digits in between ) && // then: f(n / k, m, k) // do a recursive call with n / k 
saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 80 80  79 bytes

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

Try it online!Try it online!

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 ?% k ? //  if k is greaternot thana divisor of n:  1  k > n || //  stop the recursion :  // else: n % k ? // if k is not a divisor of> n:   f(n, m, k + 1) // otherwise: 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 

JavaScript (ES6), 80 bytes

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!

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 

JavaScript (ES6),  80  79 bytes

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

Try it online!

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 ) => // n % k ? //  if k is not a divisor of n: k > n || //  stop the recursion if k > n f(n, m, k + 1) // otherwise: 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 
added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

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 

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 
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading