Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

APL, 40 13 bytes

2=+/0=x|⍨⍳x←⎕ 

Trial division with the same algorithm as my R answermy R answer. We assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this number is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

APL, 40 13 bytes

2=+/0=x|⍨⍳x←⎕ 

Trial division with the same algorithm as my R answer. We assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this number is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

APL, 40 13 bytes

2=+/0=x|⍨⍳x←⎕ 

Trial division with the same algorithm as my R answer. We assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this number is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

added 90 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120

APL, 40 13 bytes

2=+/0=x|⍨⍳x←⎕ 

Trial division with the same algorithm as my R answer. We assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this number is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

APL, 40 13 bytes

2=+/0=x|⍨⍳x←⎕ 

Trial division. We assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this number is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

APL, 40 13 bytes

2=+/0=x|⍨⍳x←⎕ 

Trial division with the same algorithm as my R answer. We assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this number is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

added 334 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120

APL, 4040 13 bytes

{(⍵>1)∧((⍵=2)∨(0<2|⍵))∧(0<⌊2=+/⍵|⍨2↓⍳⍵-1)}⎕0=x|⍨⍳x←⎕ 

Trial division. SurelyWe assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this can be made shorternumber is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

APL, 40 bytes

{(⍵>1)∧((⍵=2)∨(0<2|⍵))∧(0<⌊/⍵|⍨2↓⍳⍵-1)}⎕ 

Trial division. Surely this can be made shorter.

APL, 40 13 bytes

2=+/0=x|⍨⍳x←⎕ 

Trial division. We assign x to the input from STDIN () and get the remainder for x divided by each integer from 1 to x. Each remainder is compared against 0, which gives us a vector of ones and zeros indicating which integers divide x. This is summed using +/ to get the number of divisors. If this number is exactly 2, this means the only divisors are 1 and x, and thus x is prime.

deleted 28 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120
Loading
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120
Loading