Hot answers tagged

75 votes

The first n numbers without consecutive equal binary digits

Python 2, 36 bytes lambda n:[2**i*2/3for i in range(n)] Try it online! Explanation: The binary representation of \$\frac{2}3\$ is ...
Neil's user avatar
  • 169k
63 votes
Accepted

Binary to decimal converter

Jelly, 5 bytes DḤ+¥/ Try it online! Explanation The cast D is a monad (single argument function): digits, turning ...
Lynn's user avatar
  • 68.2k
61 votes

How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

This isn't the same solution as llhuii's, but it's also 42 bytes long. n=0;exec'print n;n^=(n^n+2)%3/2;n+=2;'*400 Try it online! Thanks to @JonathanFrech, we're ...
Dennis's user avatar
  • 210k
55 votes

Fizz Buzz to Text

C, 59 bytes i;f(char*s){while(*s&3?*s&9||(i+=i+*s%5):putchar(i),*s++);} Magic numbers, magic numbers everywhere! (Also, C shorter than Python, JS, PHP, ...
Doorknob's user avatar
  • 71.4k
45 votes

How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

Getting 39 bytes This is an explanation of how I got a 39-byte solution, which Dennis and JonathanFrech found separately as well. Or, rather, it explains how one could arrive at the answer in ...
xnor's user avatar
  • 145k
42 votes

i love yOu i lOve you i love yOu!

Jelly, 41 40 35 33 bytes Thanks to @Dennis for making the end ṖṖCG! (complement C = 1-x in ...
Jonathan Allan's user avatar
42 votes

Where's the 0xBEEF?

vim, 126 80 77 76 /\v1011\_.{9}(1110\_.{9}){2}1111<cr>:exe'norm Go'.join(getpos('.'))<cr>xxdawhPXXd{ Expects input in the form ...
Doorknob's user avatar
  • 71.4k
42 votes

Find the number of leading zeroes in a 64-bit integer

x86_64 machine language on Linux, 6 bytes 0: f3 48 0f bd c7 lzcnt %rdi,%rax 5: c3 ret Requires Haswell or K10 or ...
ceilingcat's user avatar
  • 7,485
42 votes
Accepted

Sum of Powers of 2

JavaScript (ES6), 28 bytes f=n=>n?[...f(n&~-n),n&-n]:[] Try it online!
Arnauld's user avatar
  • 191k
38 votes

Output numbers up to 2^n-1, "sorted"

Python, 53 bytes f=lambda n,i=1:n*[f]and[i]+f(n-1,2*i)+i%2*f(n-1,i-~i) Try it online! The recursive function generates the sorted list as a pre-order walk down ...
xnor's user avatar
  • 145k
35 votes

In how many bits do I fit

JavaScript (ES6), 18 bytes f=n=>n&&1+f(n>>>1) ...
ETHproductions's user avatar
31 votes

Bit run rundown

Python 2, 46 45 bytes f=lambda n,k=1:`k`in bin(n^n/2)and-~f(n,k*10) Try it online! How it works By XORing n and n/2 (dividing by 2 essentially chops off the ...
Dennis's user avatar
  • 210k
31 votes

Is the number binary-heavy?

x86 Machine Code, 15 14 bytes F3 0F B8 C1 0F BD D1 03 C0 42 2B D0 D6 C3 This is a function using Microsoft's __fastcall calling convention (first and only ...
ZH Liu's user avatar
  • 451
30 votes
Accepted

Where's the 0xBEEF?

Jelly, 20 17 16 bytes ṡ€4ḄZw€“¿ÇÇБĖUṀ Input is in form of a Boolean matrix, output is the 1-based index pair (Y, X). Try it online! or verify all test cases. ...
Dennis's user avatar
  • 210k
30 votes
Accepted

In how many bits do I fit

05AB1E, 2 bytes bg Try it online!
Magic Octopus Urn's user avatar
29 votes

Weakened Binary Walls

MATL, 4 bytes BSXB Try it at MATL Online Explanation ...
Suever's user avatar
  • 11.1k
28 votes

In how many bits do I fit

x86 Assembly, 4 bytes Assuming Constant in EBX: bsr eax,ebx inc eax EAX contains the number of bits necessary for Constant. ...
z0rberg's's user avatar
  • 399
26 votes

Only Even Bytes

GS2, 4 bytes dΦ(" Try it online! Hexdump 0000000: 64 e8 28 22 d.(" How it works ...
Dennis's user avatar
  • 210k
26 votes

Find the "Bittiest" Number

x86 Machine Language, 18 bytes 31 D2 AD F3 0F B8 F8 39 FA 77 03 87 FA 93 E2 F2 93 C3 The above bytes define a function that accepts the address of the array in ...
Cody Gray - on strike's user avatar
25 votes

Calculate the longest series of 1's in an integer's binary value

JavaScript (ES6),  33  32 bytes f=x=>x&(k=x>>1)?f(x&k):k&&1+f(k) Try it online! JavaScript (ES6),  41 40 36  34 bytes Saved 4 bytes ...
Arnauld's user avatar
  • 191k
25 votes

Find the number of leading zeroes in a 64-bit integer

Hexagony, 78 70 bytes 2"1"\.}/{}A=<\?>(<$\*}[_(A\".{}."&.'\&=/.."!=\2'%<..(@.>._.\=\{}:"<><$ Try it online! Isn't this challenge ...
DELETE_ME's user avatar
  • 17.3k
24 votes

Is it a Cyclops number? "Nobody" knows!

Python 2, 30 bytes lambda n:(2*n^2*n+3)**2==8*n+9 Try it online! Note that 2*n^2*n+3 is the bitwise xor of ...
xnor's user avatar
  • 145k
23 votes

JFor? More like XNor

Python, 34 bytes lambda a,b:bin(a&b).count('01')==1 Try it online! Although this doesn't use xor, I'm xnor.
xnor's user avatar
  • 145k
22 votes

i love yOu i lOve you i love yOu!

JavaScript (ES6), 169 ... 136 135 bytes ...
Arnauld's user avatar
  • 191k
22 votes

Where's the 0xBEEF?

JavaScript (ES6), 63 60 56 bytes s=>[(i=s.search(/1011.{9}(1110.{9}){2}1111/))%13,i/13|0] Takes input as a 155-character space-delimited string of 12 12-digit ...
Neil's user avatar
  • 169k
22 votes

Complex Binary Numbers

MATL, 7 bytes BJ*Y'^s Try it online! How it works Consider input 4538 for example. ...
Luis Mendo's user avatar
  • 104k
22 votes

Binary to decimal converter

Python 2, 49 37 31 30 Bytes Now this will take a binary number in a decimal representation, since Python can handle arbitrarily large integers. ...
Kade's user avatar
  • 7,862
22 votes

What is the reverse (binary) bit number?

Python, 29 bytes lambda n:int(bin(n)[:1:-1],2) Try it online! This is an anonymous, unnamed function which returns the result. First, ...
FlipTack's user avatar
  • 14.6k
22 votes
Accepted

Calculate the longest series of 1's in an integer's binary value

Jelly, 10 8 bytes Ba\ÐƤṀċ¬ Try it online! How it works ...
Dennis's user avatar
  • 210k

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