Hot answers tagged

74 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 ...
user avatar
  • 146k
61 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 ...
user avatar
  • 66.1k
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 ...
user avatar
  • 207k
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, ...
user avatar
  • 70.6k
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 ...
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 ...
user avatar
  • 70.6k
42 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 ...
user avatar
  • 138k
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 ...
user avatar
  • 6,847
41 votes
Accepted

Sum of Powers of 2

JavaScript (ES6), 28 bytes f=n=>n?[...f(n&~-n),n&-n]:[] Try it online!
user avatar
  • 169k
39 votes
Accepted

Count the number of ones in an unsigned 16-bit integer

80386 Machine Code, 4 bytes F3 0F B8 C1 which takes the integer in cx and outputs the count in ...
user avatar
  • 9,165
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 ...
user avatar
  • 138k
35 votes

In how many bits do I fit

JavaScript (ES6), 18 bytes f=n=>n&&1+f(n>>>1) ...
user avatar
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. ...
user avatar
  • 207k
30 votes
Accepted

In how many bits do I fit

05AB1E, 2 bytes bg Try it online!
user avatar
30 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 ...
user avatar
  • 207k
29 votes

Weakened Binary Walls

MATL, 4 bytes BSXB Try it at MATL Online Explanation ...
user avatar
  • 10.6k
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. ...
user avatar
  • 399
28 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 ...
user avatar
  • 421
26 votes

Only Even Bytes

GS2, 4 bytes dΦ(" Try it online! Hexdump 0000000: 64 e8 28 22 d.(" How it works ...
user avatar
  • 207k
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 ...
user avatar
  • 169k
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 ...
user avatar
  • 16.9k
23 votes

Numbers with multiple runs of ones

Python, 48 lambda n:[i for i in range(2**n)if'01'in bin(i)] I had been vastly overthinking this. We just need to check if the binary expansion contains ...
user avatar
  • 138k
22 votes

i love yOu i lOve you i love yOu!

JavaScript (ES6), 169 ... 136 135 bytes ...
user avatar
  • 169k
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 ...
user avatar
  • 146k
22 votes

Complex Binary Numbers

MATL, 7 bytes BJ*Y'^s Try it online! How it works Consider input 4538 for example. ...
user avatar
  • 100k
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. ...
user avatar
  • 7,753
22 votes

A bit, a nibble or byte?

Python, 39 bytes f=lambda n:4**(n>1)*(n<16)or 2*f(n**.5) Counts how many times one must take the square root for n to ...
user avatar
  • 138k
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 ...
user avatar
  • 207k
22 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 ...
user avatar
  • 138k

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