4
1
Your challenge is to write a program (full program, not a function), that will take an integer and output all prime numbers up to (including) the given integer. Output is any readable list containing all integer primes (array, string, 1 prime per line, whatever you want) and must run to stdout or equivalent.
Simple? Here's the twist:
You may not use literals in your program. These include:
- Literal numbers (0 through 9)
- Literal strings (in quotes)
You may not use built in prime checks
EDIT: A prime check is a built in function that
- Returns if a number is a prime number
- Returns a prime number
- Returns a list of prime numbers
You may code your own functions that do the above
Prime factorisation functions are allowed
As this is code-golf, shortest answer in bytes wins
6
This is an occurence of the Do X without Y problem. Not that this question is bad, just wanted to know.
– user48538 – 2016-05-27T09:13:42.7177What about prime-factorization builtins? – Denker – 2016-05-27T09:49:01.833
What if a language has a function that produces a predefined literal? Say function
f
outputs1
, can that be used instead of1
? – Luis Mendo – 2016-05-27T09:55:07.983@LuisMendo if it is really built in and not self coded, sure – 7H3_H4CK3R – 2016-05-27T09:59:07.687
7You may not use built in prime checks Does that forbid prime factorization as well (i.e. a built-in function that computes prime factors of a number)? – Luis Mendo – 2016-05-27T10:23:08.427
Is the input on the command line or STDIN or either? – Brad Gilbert b2gills – 2016-05-27T15:53:51.543
@BradGilbertb2gills doesnt matter. either are fine. – 7H3_H4CK3R – 2016-05-27T16:19:33.507
I'm voting to close as unclear because "prime checks" is not very descriptive - are builtins that compute prime factorization, nth prime, or other prime-related functions (that are not necessarily primality testing) allowed? – Mego – 2016-05-27T23:16:57.517
4
Do you have a particular reason for disallowing functions? They're allowed by default and arbitrarily overriding the defaults is one of the things to avoid when writing challenges.
– Dennis – 2016-05-28T00:17:26.2501Is 0 an integer that could be entered? Can a program end in an error for 0? – Tim – 2016-05-28T00:51:27.850
@Mego i hope to have clarified the definition. Should probably make a meta post on prime computing functions (what counts and what doesnt) – 7H3_H4CK3R – 2016-05-28T09:23:55.893
1It's still unclear to me - prime factorization functions return a list of prime numbers, so why are they allowed? And no meta post is necessary - you just have to be clearer. – Mego – 2016-05-28T09:25:21.610
@Mego i guess you have a point there, its hard to draw a boundary, but as i wrote above, Prime factorisation functions are allowed – 7H3_H4CK3R – 2016-05-28T09:26:57.657
5
If this were not already closed, I would vote to close it as a duplicate of http://codegolf.stackexchange.com/q/70001/194 . The accepted answer to that question meets all of the criteria of this one, and the others can be adapted. (Admittedly some would be more costly to adapt than others).
– Peter Taylor – 2016-05-28T09:59:18.480