Find a binary gap

Find a binary gap

GPLv3

Gần đây, mình gặp 1 bài toán khá đơn giản, nhưng thú vị như sau:

Input: A number

Output: The maximum 0 is written between the two numbers 1 in binary form with the fastest possible speed.

Ví dụ:

1
2
3
4
5
6
7
8
>>> bin(10)
'0b1010'
>>> binary_gap(10)
1
>>> bin(12)
'0b1100'
>>> binary_gap(12)
0

Continue reading
  • page 1 of 1
Author's picture

Nguyen Tien Thanh

(o.O)


Spamer


Kanagawa,Japan