Your task, if you choose to accept it, is to write a program/function that accepts an integer \$N\$ as input. The program/function should output/return a list of the first \$N\$ prime numbers. But here's the catch: you are not allowed to use prime characters in your code. A prime character is a character whose Unicode code point is a prime number. In the printable ASCII range, these are:
%)+/5;=CGIOSYaegkmq
But the rule also applies to non-ASCII characters if your code uses those.
- A valid input is an integer \$N\$ where \$0 < N \le T\$, where you can choose \$T\$, but it has to be greater than or equal to \$10000\$. \$T\$ does not have to be finite.
- For invalid inputs (non-integers, integers out of range), throw an exception or output/return nothing/null.
- An integer with leading/trailing whitespace as input is considered invalid.
- An integer with a
+
as sign character as input is considered invalid. - An integer with leading zeros as input is considered valid.
- If your language allows you to pass an already-parsed integer as input, the above parsing rules (except the range one) don't apply, because the int is already parsed.
- The input is always base-10.
- Use of built-in prime generators and primality testers (this includes prime factorization functions) is not allowed.
- The source restriction is imposed on Unicode characters, but the byte counting for the score can be in another encoding if you wish.
- The output can contain a single trailing newline, but this is not required.
- If you output/return the prime number list as a string, then every prime number must be delimited by one or multiple non-digit char(s). You can choose which delimiter you use.
- This is a code-golf challenge, the shortest code in bytes wins.
Stack Snippet to verify your code
You can use the below Stack Snippet to verify that your code does not contain prime chars:
var primes=[],max=10000;for(var i=2;i<=max;i++){primes.push(i);}for(var N=2;N<Math.sqrt(max);N++){if(primes.indexOf(N)===-1){continue;}primes=primes.filter(function (x){return x===N||x%N!==0;});}function setText(elem,text){var z=('innerText' in elem)? 'innerText' : 'textContent';elem[z]=text;}function verify(inputCode,resultSpan){var invalidChars=[];var success=true;for(var i=0;i<inputCode.length;i++){var cc = inputCode.charCodeAt(i);if (cc>max){setText(resultSpan,"Uh oh! The char code was bigger than the max. prime number calculated by the snippet.");success = false;break;}if (primes.indexOf(cc)!==-1){invalidChars.push(inputCode[i]);}}if (invalidChars.length===0&&success){setText(resultSpan, "Valid code!");}else if(success) { var uniqueInvalidChars = invalidChars.filter(function (x, i, self){return self.indexOf(x)===i;});setText(resultSpan, "Invalid code! Invalid chars: " + uniqueInvalidChars.join("")); }}document.getElementById("verifyBtn").onclick=function(e){e=e||window.event;e.preventDefault();var code=document.getElementById("codeTxt").value;verify(code,document.getElementById("result"));};
Enter your code snippet here:<br /><textarea id="codeTxt" rows="5" cols="70"></textarea><br /><button id="verifyBtn">Verify</button><br /><span id="result"></span>
;
happens to be banned... \$\endgroup\$+
, it seems disappointing to be required to manually throw these out. \$\endgroup\$