Skip to main content
fix answer
Source Link
cole
  • 4k
  • 1
  • 14
  • 26

J, 2130 bytes

>:*(-{1=[:+/0=[:|/~]+i.@[)^:>: 

Try it online!Try it online!

Takes starting value as the right argument and the value to check at the left argument.

I messed up originally and didn't account for left arguments less than the starting prime. I'm somewhat unhappy with the length of my solution now.

Explanation

Let x be the left argument (the value to check) and y be the right argument (the starting prime).

>:*(-{1=[:+/0=[:|/~]+i.@[)^:>:   ^:>: Execute left argument if x >= y i.@[  Create range [0..x]   ]+  Add y to it (range now: [y..x+y])   |/~  Form table of residues   0=  Equate each element to 0   +/  Sum columns   1=  Equate to 1  -{  Take the element at position x-y >:* Multiply by result of x >= y 

Notes

The element at position x-y is the result of primality testing for x (since we added y to the original range).

Multiplying by x >: y ensures that we get a falsey value (0) for x less than y.

J, 21 bytes

-{1=[:+/0=[:|/~]+i.@[ 

Try it online!

Takes starting value as the right argument and the value to check at the left argument.

Explanation

Let x be the left argument (the value to check) and y be the right argument (the starting prime).

-{1=[:+/0=[:|/~]+i.@[ i.@[ Create range [0..x] ]+ Add y to it (range now: [y..x+y]) |/~ Form table of residues 0= Equate each element to 0 +/ Sum columns 1= Equate to 1 -{ Take the element at position x-y 

The element at position x-y is the result of primality testing for x (since we added y to the original range).

J, 30 bytes

>:*(-{1=[:+/0=[:|/~]+i.@[)^:>: 

Try it online!

Takes starting value as the right argument and the value to check at the left argument.

I messed up originally and didn't account for left arguments less than the starting prime. I'm somewhat unhappy with the length of my solution now.

Explanation

Let x be the left argument (the value to check) and y be the right argument (the starting prime).

>:*(-{1=[:+/0=[:|/~]+i.@[)^:>:   ^:>: Execute left argument if x >= y i.@[  Create range [0..x]   ]+  Add y to it (range now: [y..x+y])   |/~  Form table of residues   0=  Equate each element to 0   +/  Sum columns   1=  Equate to 1  -{  Take the element at position x-y >:* Multiply by result of x >= y 

Notes

The element at position x-y is the result of primality testing for x (since we added y to the original range).

Multiplying by x >: y ensures that we get a falsey value (0) for x less than y.

Add explanation
Source Link
cole
  • 4k
  • 1
  • 14
  • 26

J, 21 bytes

-{1=[:+/0=[:|/~]+i.@[ 

Try it online!Try it online!

Takes starting value as the right argument and the value to check at the left argument.

Explanation

Let x be the left argument (the value to check) and y be the right argument (the starting prime).

-{1=[:+/0=[:|/~]+i.@[ i.@[ Create range [0..x] ]+ Add y to it (range now: [y..x+y]) |/~ Form table of residues 0= Equate each element to 0 +/ Sum columns 1= Equate to 1 -{ Take the element at position x-y 

The element at position x-y is the result of primality testing for x (since we added y to the original range).

J, 21 bytes

-{1=[:+/0=[:|/~]+i.@[ 

Try it online!

Takes starting value as the right argument and the value to check at the left argument.

J, 21 bytes

-{1=[:+/0=[:|/~]+i.@[ 

Try it online!

Takes starting value as the right argument and the value to check at the left argument.

Explanation

Let x be the left argument (the value to check) and y be the right argument (the starting prime).

-{1=[:+/0=[:|/~]+i.@[ i.@[ Create range [0..x] ]+ Add y to it (range now: [y..x+y]) |/~ Form table of residues 0= Equate each element to 0 +/ Sum columns 1= Equate to 1 -{ Take the element at position x-y 

The element at position x-y is the result of primality testing for x (since we added y to the original range).

Source Link
cole
  • 4k
  • 1
  • 14
  • 26

J, 21 bytes

-{1=[:+/0=[:|/~]+i.@[ 

Try it online!

Takes starting value as the right argument and the value to check at the left argument.