22
6
Introduction
Prime numbers are simple, right? Well, now you get your chance to find out!
Challenge
You must write a program or function that takes an input n
and outputs the first n
prime numbers.
Example Input and Output
Input: 10
Output: 2,3,5,7,11,13,17,19,23,29
Rules
You must not include any of the following builtin functions:
A list of prime numbers
Primality testing
Next prime
Prime factorization
List of divisors
Your output must be in a convenient, unambiguous list format.
This is code-golf, so the shortest answer in bytes wins.
Rule 2 still requires clarification. Does it cover nth prime functions? Next prime functions? Factorization? None of this makes use of a list. – Dennis – 2016-01-24T15:17:03.643
@Dennis To clarify: it covers built in prime functions, next prime function, and factorization. You need to create the prime testing function yourself. – Elliot A. – 2016-01-24T15:18:45.387
6@feersum That's most definitely not a duplicate. Your linked question involves time complexity in the scoring system. – Doorknob – 2016-01-24T15:26:45.567
2
By the way, there is no need to specify rule 1 (it applies by default), and rule 3 is one of the things to avoid when writing challenges.
– Dennis – 2016-01-24T15:36:10.7973
Are built-ins allowed that get you a list of divisors or the prime factorisation? Also, by default input and output in unary or as byte values is allowed. If that's not what you want, you should explicitly say that input and output will be decimal. And you should clarify if
– Martin Ender – 2016-01-24T16:23:20.580n
can be 0 or will always be positive.@MartinBüttner i/o in unary/byte values is allowed. Prime factorization and list of divisors are not allowed. – Elliot A. – 2016-01-24T16:35:48.953
3@ElliotA. Please edit the question when clarifying. Comments are not permanent. – Mego – 2016-01-24T18:03:03.283
5I have voted to close as a duplicate of "find the first n composite numbers" because the difference should be a single logical negation in most languages. – Peter Taylor – 2016-01-24T23:10:25.753
@PeterTaylor But, they're not the same. – Elliot A. – 2016-01-25T12:14:52.473
@ElliotA. They are related closely enough to be considered duplicates on this site. One could copy an answer from one challenge to the other with a trivial change (negating or not negating a logical condition), which makes them duplicates as far as PPCG is concerned.
– Martin Ender – 2016-01-25T16:13:57.437