Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- def isValid(n, k):
- if ('1' * int(k) in str(n)):
- return True
- return False
- # Args
- # Usage: python thisfile.py --num=5 --count=2
- # Result: 6 (0b00000110)
- parser = argparse.ArgumentParser(description='ConsecutiveOnes')
- requiredNamed = parser.add_argument_group('Required arguments')
- requiredNamed.add_argument('--num', help='Your number', required=True)
- requiredNamed.add_argument('--count', help='How many times 1 need to be repeated', required=True)
- args = parser.parse_args()
- # Let's rock
- num = int(args.num)
- binNum = bin(num)
- while isValid(binNum, args.count) is False:
- num += 1
- binNum = bin(num)
- print('Your number is %d' % (num))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement