# Input

Positive integers a and b defining an interval of integers [a .. b].

# Output

The maximum number of trailing zeros in the binary expansion of any integer in the interval [a .. b].

# Examples

Input: [17 .. 21] ; Output: 2 ; since 20 corresponds to 10100

Input: [22 .. 37] ; Output: 5 ; since 32 corresponds to 100000

• Will a and b always be low-high in that order? Commented Apr 12 at 17:19
• I'd suggest including more test cases, in particular where it matters that the interval includes its endpoints.
– xnor
Commented Apr 12 at 17:30
• Welcome to the CGCC stack, nice question! +1 on both of the above. I imagine "yes" to the first (otherwise nice solutions like xnor's will have to reorder appropriately, which does not seem core to the challenge). Commented Apr 12 at 20:03

# Python, 27 bytes

lambda a,b:len(bin(-a&b))-3


Try it online!

Thanks to Albert.Lang for -1 byte from the below, using the fact that a-1==~-a.

28 bytes

lambda a,b:len(bin(a-1^b))-3


Try it online!

Takes the xor of a-1 and b, and outputs its length in binary minus 1. (The code subtracts 3 instead because binary strings in Python are prefixed by 0b.)

37 bytes

f=lambda a,b:-(a>b)or-~f(-~a//2,b//2)


Try it online!

• lambda a,b:len(bin(-a&b))-3 appears to work just as well. Commented Apr 13 at 5:32

# Vyxal 3, 5 bytes

v⊻bLv


Try it Online!

v⊻bLv­⁡​‎‎⁪⁡⁪⁠⁪⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁪‏‏​⁡⁠⁡‌⁢​‎‎⁪⁡⁪⁠⁪⁣⁪‏⁠⁪⁪‏​⁡⁠⁡‌⁣​‎‎⁪⁡⁪⁠⁪⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁪‏‏​⁡⁠⁡‌­
v⊻     # ‎⁡xor(a-1, b)
b    # ‎⁢to binary
Lv  # ‎⁣length - 1
💎


Created with the help of Luminespire.

• @JonathanAllan The input has to be taken with the larger number on the first line and the smaller on the second line. Commented Apr 12 at 22:11
• You can save a byte by applying ᵛ to M instead of using a mapping lambda: 6 bytes ꜝR2ᵛMG Commented Apr 12 at 22:13
• (So the input in the Try it Online! link needs reversing) Commented Apr 13 at 0:23
• Port of xnor's solution is 5 bytes Commented Apr 13 at 2:57

# Perl 5-pl, 23 bytes

Same idea as @xnor's answer but uses the power of 2 rather than bitstring length to save bytes.

$_=0|log(--$_^<>)/log 2


Try it online!

# Uiua 0.11.0, 11 bytes SBCS (updated)

/↥⊗1⋯+⇡+1-,


Takes b a and returns the maximum number of trailing zeros.

## Explanation

+1-, # puts b-a+1 and a on stack
⇡    # range [0 ... b-a+1]
+    # add a to get [a ... b]
⋯    # get little-endian binary of each
⊗1   # get index of first 1 in each
/↥   # maximum


## Also 11 bytes

-1⧻⋯⍜⋯/≠⊟-1


Direct port of @xnor's answer. Takes a b.

# sed-r, 726966 59 bytes

s/(.*) (.*)/dc -e2o{\1..\2}p/e   #converts two numbers into a binary range
s/.*1//gm                        #keep only the last 0s of each line
s/.*/wc -L<<<"&"/e               #num of chars in longest line


Try it online!

I feel like if I were smarter about it there should be a way to entierly remove that second line, but this is as good as I'll be able to get it today.

more detailed explanation:

the first swap converts two numbers seperated by a space (eg, '4 9') into
dc -e2o{4..9}p. the e flag means we execute, so bash then expands that into
dc -e2o4p -e2o5p -e2o6p -e2o7p -e2o8p -e2o9p. numbers get put on the stack, o pops one number for the output base and then p prints the top of the stack in that base.

now we have binary numbers seperated by newlines. this next swap is global and multiline. we delete everything up to and including the last 1 of each line.

now we have 0s seperated by newlines. we take the full input and send it to wc(word count). -L gives the longest line, which is our output

equivalently,

bye $#l-3  Try it online! # Python, 160 bytes a, b = 17, 21 max_zeros = 0 for num in range(a, b+1): num_zeros = (num & -num).bit_length() - 1 max_zeros = max(max_zeros, num_zeros) print(max_zeros)  The expression num & -num finds the rightmost set bit of num. -num is the 2's complement of num, which flips all the bits of num and adds 1 to it. • Good first attempt. The goal is to write the shortest code possible. Can you try and see if there's a way to shorten your code? Commented Apr 15 at 11:00 # Charcoal, 13 bytes Ｉ⌈Ｅ…·ＮＮ⌕⮌⍘ι²1  Try it online! Link is to verbose version of code. Explanation:  …· Inclusive range from Ｎ First input as a number to Ｎ Second input as a number Ｅ Map over values ι Current value ⍘ Converted to base ² Literal integer 2 ⮌ Reversed ⌕ Find index of 1 Literal string 1 ⌈ Take the maximum Ｉ Cast to string Implicitly print  9 bytes if @Albert.Lang's formula is correct: Ｉ⊖Ｌ↨＆±ＮＮ²  Try it online! Link is to verbose version of code. Explanation:  Ｎ First input as a number ± Negated ＆ Bitwise And Ｎ Second input as a number ↨ Convert to base ² Literal integer 2 Ｌ Take the length ⊖ Decremented Ｉ Cast to string Implicitly print  # 05AB1E, 5 bytes ŸÓøнà  A port of @xnor's Python answer is 5 bytes as well: (&bg<  Explanation: Ÿ # Convert the (implicit) input-pair to a list in that range Ó # Map each inner value to a list of exponents of its prime factorization ø # Zip/transpose; swapping rows/columns н # Pop and only leave the first column (exponents of prime 2) à # Pop and leave the maximum # (which is output implicitly as result)  ( # Negate the first (implicit) input: -a & # Bitwise-AND it with the second (implicit) input: -a&b b # Convert it to binary g # Pop and push its length < # Decrease it by 1 # (after which it is output implicitly as result)  # Pip, 9 bytes DBL:DaBXb  Try It Online! ### Explanation Port of xnor's Python answer. DBL:DaBXb Da ; Decrement first command-line input BXb ; Bitwise XOR with second command-line input BL: ; Bit length of result D ; Decrement  # PowerShell, 97 bytes $a,$b=180,180$m=0
for($n=$a;$n-le$b;$n++){$m=[math]::Max($m,([math]::Log($n-band(-$n),2))-1)}$m


Try it online!

# C (gcc), 33

f(a,b){a=31-__builtin_clz(-a&b);}