Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Prime Difference

Parent

Prime Difference

+5
−0

Given an integer n, output the smallest prime such that the difference between it and the next prime is at least n.

For example, if n=5, you would output 23, since the next prime is 29, and 29-23>=5.

More Input/Output Examples

1 -> 2 (3 - 2 >= 1)
2 -> 3 (5 - 3 >= 2)
3 -> 7 (11 - 7 >= 3)
4 -> 7
5 -> 23
6 -> 23
7 -> 89
8 -> 89

This is code-golf, so shortest code wins.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (1 comment)
Post
+3
−0

Husk, 8 bytes

Ψḟo≥⁰≠İp

Try it online! or Verify first 8 values

It is always a good day when you get to use Ψ in your program.

Explanation

Ψḟo≥⁰≠İp
      İp to the infinite list of prime numbers,
Ψ        apply this higher order function on overlapping pairs
 ḟo      first element where
     ≠   absolute difference
   ≥⁰    is greater than or equal to the input.
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Wow, never thought I'd actually see toadj_ used somewhere. +1 (1 comment)
Wow, never thought I'd actually see toadj_ used somewhere. +1
user‭ wrote over 3 years ago

Wow, never thought I'd actually see toadj_ used somewhere. +1