Skip to main content
added 8 characters in body
Source Link
Jens Renders
  • 1.6k
  • 13
  • 26

JavaScript (ES6), 4443 bytes

This is the shortest solution so far that accepts decimal input. Also, it doesn't use regex like the other short solutions.

p=n=>--d-1?n%d?pn%d&&p(n):0:1;alert(p(d=prompt())) 

What it uses instead is a recursive function, something that wasn't very useful when you needed to write function and return , but is now very useful because of the => notation.

Ungolfed:

p=n=> // p=function(n){ return --d-1? // if --d is not 1 (decrement d) n%d?pn%d&&p(n):0  // if n divdes d, false, else rerun the function // (d has already been decremented) :1; // else (if d is 1) then true alert(p(d=prompt())) // Use the function on the input // and assign this value to d 

JavaScript (ES6), 44 bytes

This is the shortest solution so far that accepts decimal input. Also, it doesn't use regex like the other short solutions.

p=n=>--d-1?n%d?p(n):0:1;alert(p(d=prompt())) 

What it uses instead is a recursive function, something that wasn't very useful when you needed to write function and return , but is now very useful because of the => notation.

Ungolfed:

p=n=> // p=function(n){ return --d-1? // if --d is not 1 (decrement d) n%d?p(n):0 // if n divdes d, false, else rerun the function // (d has already been decremented) :1; // else (if d is 1) then true alert(p(d=prompt())) // Use the function on the input // and assign this value to d 

JavaScript (ES6), 43 bytes

This is the shortest solution so far that accepts decimal input. Also, it doesn't use regex like the other short solutions.

p=n=>--d-1?n%d&&p(n):1;alert(p(d=prompt())) 

What it uses instead is a recursive function, something that wasn't very useful when you needed to write function and return , but is now very useful because of the => notation.

Ungolfed:

p=n=> // p=function(n){ return --d-1? // if --d is not 1 (decrement d) n%d&&p(n)  // if n divdes d, false, else rerun the function // (d has already been decremented) :1; // else (if d is 1) then true alert(p(d=prompt())) // Use the function on the input // and assign this value to d 
Source Link
Jens Renders
  • 1.6k
  • 13
  • 26

JavaScript (ES6), 44 bytes

This is the shortest solution so far that accepts decimal input. Also, it doesn't use regex like the other short solutions.

p=n=>--d-1?n%d?p(n):0:1;alert(p(d=prompt())) 

What it uses instead is a recursive function, something that wasn't very useful when you needed to write function and return , but is now very useful because of the => notation.

Ungolfed:

p=n=> // p=function(n){ return --d-1? // if --d is not 1 (decrement d) n%d?p(n):0 // if n divdes d, false, else rerun the function // (d has already been decremented) :1; // else (if d is 1) then true alert(p(d=prompt())) // Use the function on the input // and assign this value to d