172
votes
Is this number a prime?
Hexagony, 29 bytes
.?'.).@@/'/.!.>+=(<.!)}($>(<%
The readable version of this code is:
...
138
votes
131
votes
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 ...
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.
...
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 ...
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:
...
49
votes
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\$ ...
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\$ ...
46
votes
Calculate Phi (not Pi)
Regex (.NET), 122 113 bytes
^(?=((?=.*$(?<=^(\3+(.+.))(.*?(?>(.\4)?)))).)+(.*))((?=.*(?=\6$)(?<=(?!(.+.)\8*(?=\6$)(?<=^\8+))(.+?(?>\9?)))).)+
...
46
votes
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 ...
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 = ...
41
votes
Is this even or odd?
Mathematica, 4 bytes
OddQ
Gives True for odd inputs and False for even inputs, who knew?
...
40
votes
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 ...
37
votes
Accepted
Sharing (characters) is Caring!
20 languages
Using ()-#*.05;=>^Vefikloqrst (24 characters) so far:
...
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 ...
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, ...
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})) ...
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 ...
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} = \...
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 ...
29
votes
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
number-theory × 457code-golf × 422
math × 171
sequence × 112
number × 98
primes × 90
arithmetic × 47
decision-problem × 40
integer × 26
combinatorics × 20
base-conversion × 16
fastest-code × 15
integer-partitions × 15
division × 13
factoring × 13
code-challenge × 10
kolmogorov-complexity × 8
binary × 8
fibonacci × 8
rational-numbers × 8
restricted-time × 8
polynomials × 7
restricted-complexity × 7
abstract-algebra × 6
permutations × 5