# Tag Info

95

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: .globl f f: bsfl %edi, %eax ret The input is given in the EDI register and returned in the EAX register as per standard 64-bit c calling conventions. Because of two's complement binary encoding,...

41

Jelly, 1 byte ḍ This took me hours to golf. Try it online!

29

Brain-Flak, 72 70 64 62 58 46 bytes {({}[()]{(<()>)}{}<({}[()]<({}())>)>)}{}{{}}{} Takes dividend and divisor (in that order) as input and prints the divisor (truthy) or nothing. Since each stack has an implicit, infinite amount of zeroes, empty output should be considered falsy. While not stack-clean, this solution uses only a single ...

27

Mathematica, 13 chars Mean@{#,0,0}&

27

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 Doubles as input and returns a Double as output. How? The hyperbolic tangent is an amazing function (two bytes shorter than signum!). x tanh x 0.0 0.0 -0.0 -0.0 Infinity 1.0 -Infinity -1.0 Haskell, 30 29 bytes x?y|x/y<=1/0=x/y|0<...

26

Python, 25 bytes lambda n:len(bin(n&-n))-3 n & -n zeroes anything except the least significant bit, e.g. this: 100010101010100000101010000 v 000000000000000000000010000 We are interested in the number of trailing zeroes, so we convert it to a binary string using bin, which for the above number will be "0b10000". Since we don't care ...

23

Jelly, 4 bytes Æfċ2 In the latest version of Jelly, ÆEḢ (3 bytes) works. Æf Calculate the prime factorization. On negative input, -1 appended to the end. ċ2 Count the 2s. Try it here.

23

Golfscript, 27 22 bytes {.9>{.10/\10%2*-f}*}:f You can use it this way: 1000f Explanation {.9>{.10/\10%2*-f}*}:f { }:f # Define block 'f' (similar to a function) . # Duplicate the first value of the stack 9>{ }* # If the value on top of the stack is greater than 9 then the block is ...

23

BitCycle, 146 79 64 bytes Just realized a whole section of my original code was unneccessary. Huge reduction! v <>! A\B^^= ? D^>^< >\v^~ D@ >/ C/ > C ^ A/B v ^ < ? D^ The program takes input in unary from the command line, with the divisor first. It outputs the quotient and remainder in unary, separated by a 0. For example, ...

21

Pyth, 6 bytes /P.aQ2 Try it here. P.aQ In the prime factorization of the absolute value of the input / 2 count the number of 2s.

19

Pyth, 5 l{yPQ Uses the subsets operation on the prime factors of the input, then keeps only the unique lists of factors and returns this count. Test Suite Explanation Using 25 as an example, so that the subset list isn't very long l{yPQ ## implicit: Q = eval(input()) so Q == 25 PQ ## Prime factors of Q, giving [5, 5] y ## All ...

19

x86_32 machine code, 8 bytes 08048550 <div7>: 8048550: 99 cdq 8048551: f7 f9 idiv %ecx 8048553: 85 d2 test %edx,%edx 8048555: 0f 94 c0 sete %al This is my first code golf answer, so hopefully I'm following all the rules. This first calls cdq to clear out ...

19

05AB1E, 2 bytes ÑO Try it online! How? Ñ Divisors O Sum

17

Writing rules is hard, these rules in particular contain incentive to avoid additions at all costs. Is there a prize for the most ridiculous answer? JavaScript - 0 additions Now with fallback method that does a hulking solution for larger a's and b's, and a slightly more compact structure in order not to bust the character limit. (Pfff, 30000 characters. ...

17

Brain-flak 102, 98, 96 bytes (({}<>))<>{({}[()])<>(({}[()])){{}(<({}[({})])>)}{}({}({}))<>}{}<>([{}]{}){<>(([()])())}({}{}()) Eww. Gross. I might post an explanation, but I barely understand it myself. This language hurts my brain. Try it online! Thanks to github user @Wheatwizard for coming up with a modulus ...

17

Hexagony, 15, 13, 12 10 bytes Everybody's favorite hexagon-based language! :D TL;DR works using magic, unformatted solutions in decreasing byte count: ?{?..>1'%<.@!'/ ?{?!1\.'%<@.> ?{?\!1@'%\!( ?{?!1\@'%< Saved 2 bytes thanks to @MartinEnder's layout wizardry. @FryAmTheEggman saved 1 byte by using the corners more creatively Both @MartinEnder ...

17

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 @TheLethalCoder. -2 bytes thanks to @Nevay. Explanation: Try it here. n->{ // Method with integer as parameter and return-type int r=0; // Result-integer (starting at 0)...

15

JavaScript (ES6), 18 bytes n=>Math.log2(n&-n) 4 bytes shorter than 31-Math.clz32. Hah.

15

brainfuck, 43 41 bytes ,<,[>->+<[>]>>>>+<<<[<+>-]<<[<]>-]>>.>>>. This uses a modified version of my destructive modulus algorithm on Esolangs. The program reads two bytes – d and n, in that order – from STDIN and prints two bytes – n%d and n/d, in that order – to STDOUT. It requires a ...

15

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 n => n % eval([...n + n].join+) n => // take input string n -> e.g. "80" n + n // double the input -> "8080" [...

14

C++ C, 43 57 56 46 43 bytes On Martin Büttner's suggestions : i,c;f(n){for(i=c=n;i;n%i--&&--c);return c;}

14

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

14

Haskell, 45 37 34 bytes (+)>>=until((reverse>>=(==)).show)

14

05AB1E, 2 bytes ÑP Try it online! Explanation Ñ # divisors P # product

14

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 lambda n,k:n%k>>n*10%k*n Try it online! The *n at the end can't be omitted, say for n=19001, k=10000.

13

C Not exactly a long division - this answer uses the method used in the real old days. #include <stdio.h> #include <stdlib.h> int main() { int a,b; scanf("%d %d", &a, &b); int *p=calloc(b, sizeof(int)); int *q=p; while(a--) { (*p)++; if(p-q<b-1) p++; else p-=b-1; } p=q; int r=0, ...

13

Haskell, 35 bytes until(<71)(\n->div n 10-2*mod n 10) Usage example: until(<71)(\n->div n 10-2*mod n 10) 36893488147419103232 -> 32. Nothing much to explain, it's a direct implementation of the algorithm.

13

Pyth, 7 bytes *f_I*Q Try it online: Demonstration Explanation *f_I*QT)Q implicit endings, Q=input number f ) find the first number T >= 1, which satisfies: *QT product of Q and T ` as string _I is invariant under inversion (=palindrom) * Q multiply this number with Q and print

13

Funciton, 224 108 bytes Byte count assumes UTF-16 encoding with BOM. ┌──┬───┐ ┌┴╖╓┴╖ ┌┴╖ │%╟║f╟┐│÷╟┘ ╘╤╝╙─╜│╘╤╝ └────┴─┘ Try it online! The above defines a function f, which takes two integers and returns both their division and their product (functions in Funciton can have multiple outputs as long as the sum of inputs and outputs doesn't exceed 4). ...

13

Oasis, 4 bytes Code: nj+U Try it online! Explanation: Extended version: nj+00 0 = a(0) 0 = a(1) a(n) = n # Push n j # Get the largest divisor under n + # Add to a(n - 1)

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