Skip to main content
97 votes

How even is a number?

x86_64 machine code, 4 bytes The BSF (bit scan forward) instruction does exactly this! 0x0f 0xbc 0xc7 0xc3 In gcc-style assembly, this is: ...
Digital Trauma's user avatar
41 votes

Divisibility test

Jelly, 1 byte This took me hours to golf. Try it online!
DJMcMayhem's user avatar
  • 59.2k
31 votes

How even is a number?

Python, 25 bytes lambda n:len(bin(n&-n))-3 n & -n zeroes anything except the least significant bit, e.g. this: ...
orlp's user avatar
  • 39.1k
30 votes

Implement Ash's float division

Haskell, 35 bytes x?y|isNaN$x/y=tanh x*tanh y|0<1=x/y Try it online! The relevant function is (?), which takes two ...
Delfad0r's user avatar
  • 6,266
29 votes

Divisibility test

Brain-Flak, 72 70 64 62 58 46 bytes {({}[()]{(<()>)}{}<({}[()]<({}())>)>)}{}{{}}{} Takes dividend and divisor (in that order) as input and ...
Dennis's user avatar
  • 210k
25 votes

Division and remainder

BitCycle, 146 79 64 bytes Just realized a whole section of my original code was unneccessary. Huge reduction! ...
DLosc's user avatar
  • 39.5k
23 votes

Implement the divisibility-by-7 rule

Golfscript, 27 22 bytes {.9>{.10/\10%2*-f}*}:f You can use it this way: 1000f Explanation ...
Dica's user avatar
  • 411
22 votes

How even is a number?

Jelly, 4 bytes Æfċ2 In the latest version of Jelly, ÆEḢ (3 bytes) works. ...
lirtosiast's user avatar
  • 21.5k
22 votes

Find the sum of the divisors of N

05AB1E, 2 bytes ÑO Try it online! How? Ñ Divisors O Sum
H.PWiz's user avatar
  • 11.6k
21 votes

How even is a number?

Pyth, 6 bytes /P.aQ2 Try it here. ...
lirtosiast's user avatar
  • 21.5k
19 votes

Divisibility test

x86_32 machine code, 8 bytes ...
davey's user avatar
  • 421
19 votes

Divisibility Streak

Java 8, 44 42 41 39 bytes Crossed out 44 is still regular 44 ;( n->{int r=0;for(;~-n%--r<1;);return~r;} -2 bytes thanks to @LeakyNun. -1 byte thanks to @...
Kevin Cruijssen's user avatar
17 votes

Divisibility test

Brain-flak 102, 98, 96 bytes ...
DJMcMayhem's user avatar
  • 59.2k
17 votes

Divisibility test

Hexagony, 15, 13, 12 10 bytes Everybody's favorite hexagon-based language! :D TL;DR works using magic, unformatted solutions in decreasing byte count: ...
Blue's user avatar
  • 2,036
16 votes

How even is a number?

JavaScript (ES6), 18 bytes n=>Math.log2(n&-n) 4 bytes shorter than 31-Math.clz32. Hah.
Patrick Roberts's user avatar
16 votes

Semidivisibility

Python 2, 24 bytes lambda n,k:n*10%k==0<n%k Try it online! Checks that \$10n\$ is a multiple of \$k\$, but \$n\$ itself is not. 24 bytes ...
xnor's user avatar
  • 145k
15 votes

How even is a number?

JavaScript ES6, 22 19 bytes f=x=>x%2?0:f(x/2)+1 Looks like recursion is the shortest route.
ETHproductions's user avatar
15 votes

Division and remainder

Funciton, 224 108 bytes Byte count assumes UTF-16 encoding with BOM. ┌──┬───┐ ┌┴╖╓┴╖ ┌┴╖ │%╟║f╟┐│÷╟┘ ╘╤╝╙─╜│╘╤╝ └────┴─┘ Try it online! The above defines a ...
Martin Ender's user avatar
15 votes

Division and remainder

brainfuck, 43 41 bytes ,<,[>->+<[>]>>>>+<<<[<+>-]<<[<]>-]>>.>>>. This uses a modified ...
Dennis's user avatar
  • 210k
15 votes

Am I divisible by double the sum of my digits?

JavaScript (ES6), 31 29 27 bytes Takes input as a string. Returns zero for truthy and non-zero for falsy. n=>n%eval([...n+n].join`+`) Commented ...
Arnauld's user avatar
  • 192k
14 votes

Smallest palindrome divisible by the input

Haskell, 45 37 34 bytes (+)>>=until((reverse>>=(==)).show)
Damien's user avatar
  • 2,447
14 votes

Product of Divisors

05AB1E, 2 bytes ÑP Try it online! Explanation Ñ # divisors P # product
Emigna's user avatar
  • 53k
13 votes

Implement the divisibility-by-7 rule

Haskell, 35 bytes until(<71)(\n->div n 10-2*mod n 10) Usage example: ...
nimi's user avatar
  • 35.8k
13 votes

Smallest palindrome divisible by the input

Pyth, 7 bytes *f_I`*Q Try it online: Demonstration Explanation ...
Jakube's user avatar
  • 21.9k
13 votes

Proper Divisor mash-up

Oasis, 4 bytes Code: nj+U Try it online! Explanation: Extended version: ...
Adnan's user avatar
  • 44.4k
13 votes

Implement Ash's float division

JavaScript (ES6), 45 bytes Expects (a)(b), as Numbers. Returns a Number. ...
Arnauld's user avatar
  • 192k
12 votes
Accepted

Divinacci Sequence

05AB1E, 9 bytes XÎFDŠ‚ÑOO Try it online! Explanation ...
Emigna's user avatar
  • 53k
12 votes

How many times, are they multiples?

05AB1E, 5 bytes ŸÑ˜åO Try it online! Explanation ...
Expired Data's user avatar
  • 4,001
12 votes

Implement Ash's float division

Julia 0.7, 26 bytes imaginary brownie points for using tanh instead of sign (thanks Delfad0r) ...
MarcMush's user avatar
  • 6,495

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