139 votes

Calculate the number of primes up to n

C, 0.026119s (Mar 12 2016) ...
Dennis's user avatar
  • 210k
131 votes

Is this even or odd?

ArnoldC, 299 283 bytes ...
Luis Mendo's user avatar
  • 104k
67 votes

Coprimes up to N

Python 2, 61 47 bytes lambda n:[k/n for k in range(n*n)if k/n*k%n==1] Try it online! Background Consider the ring \$(Z_n, +_n, \cdot_n)\$. While this ring is ...
Dennis's user avatar
  • 210k
53 votes

Is this number a prime?

Hexagony, 28 bytes Since Etoplay absolutely trounced me on this question, I felt that I had to outgolf his only other answer. ...
H.PWiz's user avatar
  • 11.6k
52 votes

Is this even or odd?

brainfuck, 8 bytes +[,>,]<. Input is in unary. Output is the 1 (truthy) for odd numbers and NUL (falsy) for even numbers. Try it online! How it works We ...
Dennis's user avatar
  • 210k
50 votes

Theoretically output Graham's number

Binary lambda calculus, 114 bits = 14.25 bytes Hexdump: 00000000: 4457 42b0 2d88 1f9d 740e 5ed0 39ce 80 DWB.-...t.^.9.. Binary: ...
Anders Kaseorg's user avatar
49 votes

Compute the Carmichael function

Mathematica, 16 bytes CarmichaelLambda Well...
Martin Ender's user avatar
48 votes
Accepted

Is it a Proth number?

Jelly, 5 bytes ’&C²> Try it online! or verify all test cases. Let \$\newcommand{\&}[]{\text{ & }}j\$ be a strictly positive integer. \$j + 1\$ ...
Dennis's user avatar
  • 210k
48 votes

Is it a Proth number?

Python, 22 bytes lambda N:N-1&1-N>N**.5 This is a port of my Jelly answer. Test it on Ideone. How it works Let \$\newcommand{\&}[]{\text{ & }}j\$ ...
Dennis's user avatar
  • 210k
46 votes

Abandon all squares, ye who divide me

05AB1E, 2 bytes fP Try it online! How it works ...
Dennis's user avatar
  • 210k
41 votes

Theoretically output Graham's number

Haskell, 41 bytes i=((!!).).iterate i(($3).i(`i`1)(*3))4 64 Explanation: (`i`1)f n = ...
Anders Kaseorg's user avatar
41 votes

Is this even or odd?

Mathematica, 4 bytes OddQ Gives True for odd inputs and False for even inputs, who knew? ...
Martin Ender's user avatar
40 votes
Accepted

Greatest Common Divisor

Retina, 16 ^(.+)\1* \1+$ $1 This doesn't use Euclid's algorithm at all - instead it finds the GCD using regex matching groups. Try it online. - This example ...
Digital Trauma's user avatar
37 votes
Accepted

Sharing (characters) is Caring!

20 languages Using  ()-#*.05;=>^Vefikloqrst (24 characters) so far: ...
Lynn's user avatar
  • 68.7k
32 votes

Is this even or odd?

Taxi, 1,482 1,290 1,063 1,029 1,009 bytes I've never written a program in Taxi before and I'm a novice in programming for general, so there are probably better ways to go about this. I've checked for ...
Engineer Toast's user avatar
32 votes

Is this number evil?

JavaScript (ES6), 18 bytes f=n=>n?!f(n&~-n):1 Try it online! Explanation The bitwise logic goes like this: For integers, ...
Arnauld's user avatar
  • 192k
32 votes
Accepted

Make 1s using a bunch of 1s

score = 82 71 69 (34 ‘1’s + 23 ‘+’s + 12 parenthesis pairs) $$\begin{multline*} 11111111111 = 1 + (1 + 1) \cdot {} \\ (1 + 1 + 1 + (1 + 1)^{(1 + 1)^{1 + 1 + 1}}(1 + ((1 + 1)(1 + 1 + 1))^{1 + 1 + 1})) ...
Anders Kaseorg's user avatar
30 votes

Greatest Common Divisor

i386 (x86-32) machine code, 8 bytes (9B for unsigned) +1B if we need to handle b = 0 on input. amd64 (x86-64) machine code, 9 bytes (10B for unsigned, or 14B 13B ...
Peter Cordes's user avatar
  • 4,817
30 votes
Accepted

Longest Prime Sums

Score 100 8605 I used an algorithm that starts with one solution and repeatedly tries to split a prime \$p\$ in the solution into two other primes \$q_ 1\$ and \$q_ 2\$ that satisfy \$\frac1{p-1} = \...
Greg Martin's user avatar
  • 15.7k
30 votes

Egyptian fraction representations of 1

Python 2, 42 bytes f=lambda n,x=1:1/n*[x]or[x+1]+f(n-1,x*-~x) Try it online! The key thing to observe is that ...
dingledooper's user avatar
  • 22.7k
29 votes

Write it into number theory style

671 ...
Anders Kaseorg's user avatar
29 votes
Accepted

How to solve the LCM in 50 bytes of Python

My solution to 50 bytes: v=1 for x in input().split()*6**6:v+=-v%int(x) print(v) Explanation The solution itself is relatively simple, but finding it was ...
dingledooper's user avatar
  • 22.7k
28 votes

Compute the Carmichael function

Python, 76 73 67 bytes f=lambda n,k=1:1-any(a**-~k*~-a**k%n for a in range(n))or-~f(n,k+1) Try it online! A further byte could be saved by returning True instead ...
Dennis's user avatar
  • 210k
28 votes

Find the 10-adic cube root of 3

Python 2, 33 bytes lambda k:pow(3,10**k*2/3+1,10**k) Try it online! The pow function efficiently computes the modular ...
xnor's user avatar
  • 145k
27 votes

Find the smallest positive integer which has all integers from 1 to n as factors

Python, 46 bytes g=lambda n,c=0:n<1or(c%n<1)*c or g(n,c+g(n-1)) Take that, past xnor! 50 bytes: ...
xnor's user avatar
  • 145k
26 votes
Accepted

Is this number Loeschian?

Jelly, 11 9 bytes ÆF‘%3,2ḄȦ Try it online! or verify all test cases. Background In Elementary results on the binary quadratic form a² + ab + b², the author proves ...
Dennis's user avatar
  • 210k
26 votes

Approximate Brun's Constant

Python 3, 78 77 75 70 68 62 bytes f=lambda n,k=3,m=1,j=0:k<n and-m%k*j*2/k+f(n,k+2,m*k**4,m%k/k) Thanks to @xnor for golfing off 2 4 bytes and paving the way ...
Dennis's user avatar
  • 210k

Only top scored, non community-wiki answers of a minimum length are eligible