Skip to main content
76 votes

Print some JSON

Python 2, 14 bytes print{`str`:1} Outputs: {"<type 'str'>": 1} The backticks get the string representation in Python ...
xnor's user avatar
  • 147k
42 votes

Print some JSON

jq, 6 characters (3 characters code + 3 characters command-line option.) env CW because I am sure this is not the kind of answer you intended to allow. Sample ...
35 votes

Turing-Complete Language Interpreter

Vim, interpreting Malbolge Unshackled, 2010 bytes ...
Aaroneous Miller's user avatar
33 votes

Print some JSON

Jelly, 11 bytes “Ɠɼ'ẸẠḌȷżÑ» Try it online! Output {"Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch":0}
Dennis's user avatar
  • 211k
32 votes

Put together a Senate majority

Bubblegum, 165 164 163 162 161 160 bytes ...
Anders Kaseorg's user avatar
31 votes

What an Odd Function

Jelly, 7 bytes Æf^<¥4P Swaps 2s and 3s in the input's prime factorization. The probability of odds is 2/3. Try it online! How it works ...
Dennis's user avatar
  • 211k
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.9k
27 votes

Give me odd, even, square, cube, prime and composite 3-digit numbers

Python 2, 25 22 bytes lambda s:hash(s)%591^1 Try it online! Takes input in upper case and returns the following numbers: ...
ovs's user avatar
  • 60.6k
26 votes

Infinitely many ℕ

Scratch 3.0, 13 20 blocks/121 70 bytes As SB Syntax: define(n)(i say(i ((n)+<(i)=(n)>)((1)+((i)*<(i)<(n This says each term in the sequence. A delay ...
lyxal's user avatar
  • 34.3k
26 votes

Be big more often

Python, 41 bytes lambda l:choices(l,l) from random import* Attempt This Online! or run it 100000 times Uses the list itself as the weights.
MTN's user avatar
  • 783
23 votes

Print some JSON

Notepad, 7 keystrokes If you have a Windows computer with the Notepad program, type this: {"F5":0} On my Windows 7 computer, at least, this gives you something like: ...
ETHproductions's user avatar
21 votes
Accepted

Demonstrate some advanced abstract algebra

Proof of impossibility The only anti-distributive operator when \$S=\mathbb Z\$ is such that \$\forall a, \forall b, a*b=0\$. Indeed, suppose that \$*\$ is anti-distributive. Then \$*\$ has the ...
Robin Ryder's user avatar
  • 15.6k
20 votes

f(g(x)) decreases while g(f(x)) increases

Python, 68 characters f=lambda x:(1-x%2*2)*(2*x*x+(x<0)) g=lambda x:(1-x%2*2)*(2*x*x+(x>0)) f maps negative numbers to odd numbers and positive numbers to ...
user1502040's user avatar
  • 3,864
20 votes

Bijective function ℤ → ℤⁿ

Alice, 14 12 bytes /O \i@/t&Yd& Try it online! Inverse function (not golfed): /o Q \i@/~~\ /dt&Z Try it ...
Martin Ender's user avatar
19 votes

Infinitely many ℕ

Husk, 2 bytes ḣN Try it online! First Husk answer! Also uses the sequence in the question How it works ...
caird coinheringaahin g's user avatar
18 votes

Injection from two strings to one string

brainfuck, 30 29 27 23 bytes ,[-[+.>]-[>+<---]>.-.,] Try it online! Inputs are separated by a 0x01 byte. This ...
Doorknob's user avatar
  • 71.7k
18 votes

Enumerate all pure sets

Python, 43 bytes f=lambda x:[f(i)for i in range(x)if x>>i&1] Attempt This Online! Outputs the \$ n \$th set, starting at \$ 0 \$. One way of creating a sequence of all pure sets is to encode ...
pxeger's user avatar
  • 24.6k
18 votes

Create a nibble shorthand

MATL, 12 7 bytes t~Pv1YG Input is a 4-digit binary vector. Example outputs (or try it at MATL Online!): Input [0 1 0 0]: ...
Luis Mendo's user avatar
  • 105k
17 votes

Print some JSON

Java (JDK 10), 20 bytes v->"{\"\":"+1/.3+"}" Try it online! Output {"":3.3333333333333335}
Olivier Grégoire's user avatar
17 votes

Golf a bijection within the natural numbers which map the primes to a proper subset of the primes

Mathematica, 54 48 bytes ±(t=x_?PrimeQ)=NextPrime@x ±n_:=Abs[n-1]/.t:>x-1 Defines the following bijection: ...
Martin Ender's user avatar
17 votes

Walk Across a Keyboard

Python 2, 83 bytes lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0] import re Try it online! Walks the entire keyboard until the word ...
TFeld's user avatar
  • 19.9k
17 votes

Injection from two strings to one string

JavaScript (ES6), 14 bytes Takes input as an array of 2 strings. Inspired by Luis' answer. JSON.stringify Try it online! JavaScript (ES6),  21  20 bytes Takes ...
Arnauld's user avatar
  • 198k
17 votes

Output an infinitely proportional sequence

05AB1E, 2 bytes Óθ Attempt This Online! Returns the exponent of the largest prime factor of \$n\$. Proof of correctness Let's look at the ratio between the number ...
Command Master's user avatar
16 votes

f(g(x)) decreases while g(f(x)) increases

CJam (17 bytes) Function f (named F because CJam only allows upper-case names): {W1$2b,#*}:F Function g (anonymous): ...
Peter Taylor's user avatar
  • 43.1k
16 votes

f(g(x)) decreases while g(f(x)) increases

Python, 40 bytes f=lambda x:x*(-1)**x g=lambda x:3*f(x)+1 Try it online! Some outputs are floats that equal integers because ...
xnor's user avatar
  • 147k
16 votes

Transform characters of your choice into "Hello, world!"

Perl 5, 8 bytes −1 byte by Sisyphus. y;yav;ol Input: Heavy, world! Try it online!
Anders Kaseorg's user avatar
16 votes

Print 4 billion if statements

Python 3, 70 bytes print("def f(n):f",*range(2**33),sep="==n==print('eovdedn'[n&1::2]);") Try it online (with ...
xnor's user avatar
  • 147k
15 votes

Print some JSON

JavaScript, 17 15 bytes Thanks to @Neil for this one. Call with no input. _=>`{"${_}":0}` Outputs ...
jrich's user avatar
  • 4,146

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