Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def stepCount(n):
- n = int(n)
- steps = 0
- while n > 1:
- if n % 2 == 0:
- n = n // 2
- elif n == 3 or n % 4 == 1:
- n = n - 1
- else:
- n = n + 1
- steps += 1
- print(steps)
- return steps
- def bin_2_decimal(binary):
- binary1 = binary
- decimal, i, n = 0, 0, 0
- while binary != 0:
- dec = binary % 10
- decimal = decimal + dec * pow(2, i)
- binary = binary//10
- i += 1
- print(decimal)
- if __name__ == "__main__":
- with open("test_input.txt", "r") as file:
- for line in file:
- stepCount(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement