New answers tagged primes
0
votes
What is the average of n, the closest prime to n, the square of n and the closest Fibonacci number to n?
Haskell, 150 bytes
...
1
vote
Gödel numbering of a string
Haskell, 95 bytes
e=(product.zipWith(^)[p|p<-[2..],all((>0).mod p)[2..p-1]]<$>).mapM(`lookup`zip"0s~|A()"[1,3..])
Try it online!
1
vote
Goldbach partitions
Regex 🐇 (ECMAScriptRME / Perl / PCRE), 38 bytes
^(x+)(?!(.*(?=\1$))?((xx+)\4+$|x?$))\1
Try it on replit.com! - ECMAScript (...
1
vote
Can the number reach 1 by repeatedly subtracting the largest prime less than it?
05AB1E, 7 bytes
ΔD<ÅPà-
Outputs 2 as falsey (only 1 is truthy in 05AB1E).
Try it online ...
0
votes
Is it a semiprime?
cQuents, 5 bytes
2=Lq$
Try it online!
1 for truthy, 0 for falsey.
Explanation
...
0
votes
6
votes
The program that will find the next prime number
Regex 🐇 (PCRE2 v10.35 or later), 80 77 bytes
^(?=(?*(x+?)(x*$))(?!(?*(xx+)(x+$))(?=\3*(x+))(?=\4\5(x*))\6\2\3*$))\2x+|\B|$
...
1
vote
Approximate Brun's Constant
Vyxal sḋ, 13 bytes
ʁ~æ2l'÷ε2=;fĖ
Try it online or verify all test cases.
Explanation:
...
0
votes
List of primes under a million
C (gcc), 59 bytes
i;main(n){for(;n++<1e6;dprintf(i,"%d ",n))for(i=n;n%--i;);}
dprintf(3) prints to file ...
1
vote
Prime counting function
C (clang), 49 bytes
p(n,i){for(i=n;--i&&n%i;);return--n?p(n)+!--i:0;}
Assumes n is positive.
Try it online!
0
votes
Is it a super-prime?
C (clang), 92 bytes
#define s for(i=e;--i&&e%i;p+=i<3)
p,r,i;m(e){s;for(p=r=i==e%2;--e;)s;e=p+1;s;return 1<i<r;}
Try it online!
1
vote
Prime counting function
Python 2, 55 bytes
n=input()
s=p=i=1
while i<n:p*=i*i;i+=1;s+=p%i
print~-s
Try it online!
A programification of the below. The Python 3 equivalent is 62 bytes.
...
1
vote
Prime counting function
Vyxal l, 2 bytes
¡Ǐ
Try it Online! - test cases only
This is the same as the 3 byte answer below except the length is taken by ...
0
votes
Is it a super-prime?
05AB1E, 6 bytes
.Ø>‚pß
Try it online! - 05AB1E
Try it online! - 05AB1E - test cases only
Try it online! - 05AB1E (legacy) - test cases only
Equal in length to ...
2
votes
Is it a super-prime?
Vyxal g, 4 bytes
¡†"æ
Try it Online! - test cases only
This is the same as the 5 byte answer below except the minimum is ...
1
vote
Calculate the prime factors
Regex (.NET), 31 bytes
((?=(xx+?)\2*$)(x+)\3*(?=\3$))*
Takes its input in unary, as a string of x characters whose length ...
Top 50 recent answers are included
Related Tags
primes × 320code-golf × 274
math × 85
number-theory × 84
sequence × 63
number × 61
decision-problem × 33
code-challenge × 26
integer × 18
factoring × 18
fastest-code × 14
arithmetic × 11
restricted-source × 11
string × 9
kolmogorov-complexity × 8
fibonacci × 8
ascii-art × 6
binary × 6
base-conversion × 6
cops-and-robbers × 6
source-layout × 5
array × 4
combinatorics × 4
date × 4
python × 4