Last active
October 3, 2015 20:38
-
-
Save yuheiomori/2522660 to your computer and use it in GitHub Desktop.
CodeEval Bits Positions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# def to_bin(n): | |
# result = '' | |
# while n > 0: | |
# result = str(n % 2) + result | |
# n /= 2 | |
# return result | |
def is_same_digit_on(n, p1, p2): | |
# b = to_bin(n) | |
b = "{:b}".format(n) | |
if b[len(b)-p1] == b[len(b)-p2]: | |
return 'true' | |
else: | |
return 'false' | |
if __name__ == '__main__': | |
test_cases = open(sys.argv[1], 'r') | |
for line in test_cases: | |
n, p1, p2 = [int(e) for e in line.split(',')] | |
print(is_same_digit_on(n, p1, p2)) | |
test_cases.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment