172 votes

Is this number a prime?

Hexagony, 29 bytes .?'.).@@/'/.!.>+=(<.!)}($>(<% The readable version of this code is: ...
Etoplay's user avatar
  • 3,401
138 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

Calculate Phi (not Pi)

Regex (.NET), 122 113 bytes ^(?=((?=.*$(?<=^(\3+(.+.))(.*?(?>(.\4)?)))).)+(.*))((?=.*(?=\6$)(?<=(?!(.+.)\8*(?=\6$)(?<=^\8+))(.+?(?>\9?)))).)+ ...
n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳'s user avatar
46 votes

Abandon all squares, ye who divide me

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

Well that's odd... no wait, that's even!

CJam, 18 17 13 bytes Thanks to aditsu for saving 4 bytes. qW:O%eu~"eo"= Try the test suite here. (The test suite is too long for the permalink. Just copy them ...
Martin Ender's user avatar
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

Is this number a prime?

Mornington Crescent, 2448 bytes We're back in London! ...
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.1k
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
  • 188k
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,757
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.4k
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.3k
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.3k

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