Skip to main content
Share Your Experience: Take the 2024 Developer Survey
64 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.7k
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
27 votes

What base is this number in?

Python, 27 22 bytes lambda s:(max(s)-8)%39 This requires the input to be a bytestring (Python 3) or a bytearray (Python 2 and 3). Thanks to @AleksiTorhamo for ...
Dennis's user avatar
  • 210k
27 votes

Find the polynomial

Jelly, 3 bytes ‘b@ Try it online! Returns the polynomial as a list of coefficients. Since we know the polynomial has non-negative integer coefficients, f(b) ...
Doorknob's user avatar
  • 71.5k
26 votes
Accepted

Converting "0xUsernames"

05AB1E, 4 bytes D1ìH Explanation ...
Osable's user avatar
  • 1,338
22 votes

What base is this number in?

Python, 25 bytes lambda x:int(max(x),36)+1 Defines a lambda that takes the string x. Finds the largest digit in the string (...
Riker's user avatar
  • 7,840
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,872
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.7k
21 votes

The best base is 10... Let's reach it!

Mathematica, 56 bytes #//.x_/;(b=Max[d=IntegerDigits@x]+1)<11:>d~FromDigits~b& Try it online! (Using Mathics.) I thought I'd check out what the ...
Martin Ender's user avatar
20 votes

Convert a 32 bit binary IPv4 address to its quad-dotted notation

x86-16 machine code, IBM PC DOS, 54 47 45 bytes Binary: ...
640KB's user avatar
  • 11.9k
19 votes

Converting "0xUsernames"

JavaScript (ES6), 15 bytes s=>'0x1'+s-0||s How it works '0x1'+s converts the input into a literal hexadecimal string with ...
ETHproductions's user avatar
18 votes

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

Jelly, 6 bytes Ḷ2*ẆS€ This qualifies for the imaginary bonus. Try it online! How it works ...
Dennis's user avatar
  • 210k
18 votes

Does base n have any Rotate-Left-Double numbers?

05AB1E, 6 5 bytes ÍD<&Ā -1 byte thanks to @xnor and @Noodle9. Try it online or verify the first \$[2,100]\$ test cases. Explanation: ...
Kevin Cruijssen's user avatar
17 votes
Accepted

What base is this number in?

Jelly, 4 bytes ṀØBi Requires uppercase. Try it online! or verify all test cases. How it works ...
Dennis's user avatar
  • 210k
17 votes

What is the reverse (binary) bit number?

Python, 29 bytes lambda n:int(bin(n)[:1:-1],2) Try it online
mbomb007's user avatar
  • 23.4k
17 votes

French license plates

Pure Bash (no external utils), 64 2 bytes saved thanks to @NahuelFouilleul x={A..Z} eval f=($x$x-%03d-$x$x) printf ${f[$1/1000]} $[$1%1000] Try it online! - ...
Digital Trauma's user avatar
16 votes

Smallest Zeroless Base

Pyth, 6 bytes f*FjQT Verify all the test cases. How it works f*FjQT ~ Full program. f ~ First positive integer where the condition is truthy. jQT ~ ...
Mr. Xcoder's user avatar
  • 42.4k
16 votes
Accepted

Take a byte out of it!

Jelly, 6 bytes BḄ-8ƤṀ A monadic link taking a number and returning a number. Try it online! How? Uses a nice quick, Ƥ, ...
Jonathan Allan's user avatar
15 votes

Up go the bits!

Python 2, 31 bytes f=lambda n:n and 3*f(n/2)+n%2+1 Try it online!
Dennis's user avatar
  • 210k
14 votes

Binary to decimal converter

05AB1E, 6 bytes Code: $¦v·y+ For the explantion, let's take the example 101010. We start with the number 1 (which is represented by the first digit). After that,...
Adnan's user avatar
  • 44.4k
14 votes

Split me in half

Pyth, 18 bytes u+QiR2smc2+0dt#.BM Test suite This code does something very tricky and clever with u, Pyth's fixed point ...
isaacg's user avatar
  • 42k
13 votes
Accepted

X+Y=Z - but in which base?

Jelly, 16 11 7 bytes _/N,‘FṀ This approach is heavily based on @beaker's Octave answer. Input format is Z, Y, X, with little-endian digit order, using the digit ...
Dennis's user avatar
  • 210k
13 votes
Accepted

Count down from "Infinity"

Jelly, 15 10 bytes -5 bytes thanks to @Dennis (convert directly from base 256 after ordinal cast) Oḅ⁹µBCḄµÐĿ TryItOnline! How? ...
Jonathan Allan's user avatar
13 votes

What is the reverse (binary) bit number?

JavaScript (ES6), 30 28 bytes Saved 2 bytes thanks to @Arnauld f=(n,q)=>n?f(n>>1,q*2|n%2):q This basically calculates the reverse one bit at a time: We ...
ETHproductions's user avatar
13 votes

Calculate the binary split sum of a word

Python 2, 86 81 76 bytes -5 bytes thanks Adnan -5 bytes thanks xnor s=0 for c in input():s=s*128+ord(c) print eval(bin(s).replace('01','0+0b1')) Try it online! ...
Rod's user avatar
  • 18.4k
13 votes
Accepted

Custom Number Base Converter

MATL, 2 bytes Za Try it online! All test cases. For the Za lord!
Sundar R's user avatar
  • 6,612
13 votes
Accepted

French license plates

Perl 5 (-ap), 47 bytes $_=AAAA000;$_++while$F[0]--;s/(..)(\d+)/-$2-$1/ Try it online! PHP, 74 bytes ...
Grimmy's user avatar
  • 15.7k
12 votes

Output N in base -10

JavaScript (ES6), 51 45 37 bytes f=n=>n&&n%10+((k=n<0)+f(k-n/10|0))*10 Test cases ...
Arnauld's user avatar
  • 193k
12 votes

Those Greedy Romans!

Plain English, 1059 1025 678 641 451 399 bytes Saved 34 bytes by removing an error trap. Then saved 384 bytes by golfing. Then saved 190 bytes by combining the division operation with the append ...
Jasper's user avatar
  • 449
12 votes

Smallest Zeroless Base

C,  52  50 bytes i,k;f(n){for(i=2,k=n;k;)k=k%i++?k/--i:n;return i;} Try it online! C (gcc),  47  45 bytes ...
Steadybox's user avatar
  • 16.5k

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