-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fuel2.py
62 lines (53 loc) · 1.12 KB
/
Fuel2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
##############################
# Solve the Fuel Injection Perfection problem.
# You know where it comes from.
##############################
def Cal(num):
b = num
print("Input:", bin(b), b)
counter = 0
while b > 3:
counter += 1
if b % 2 == 0:
b = b >> 1
print("#", counter, bin(b), b)
else:
c = b
#print(bin(c))
len1 = 0
while c % 2 == 1:
c = c >> 1
len1 += 1
#print(len1)
if len1 > 1:
b += 1
else:
b -= 1
print("#", counter, bin(b), b)
counter += (b - 1)
print("Extra:", (b - 1))
print("Result:", num, bin(num), counter)
print("---------------")
return counter
#for i in range (1, 2 ** 11):
# Cal(i)
Cal(1)
Cal(2)
Cal(3)
Cal(4)
Cal(2**4)
Cal(2**4 - 1)
Cal(2**4 - 2)
Cal(2**4 - 3)
Cal(0b11000011)
Cal(0b11000011111)
Cal(0b11000001111)
Cal(0b11000101111)
#Cal(2**10 + 1)
#Cal(2**300 + 1)
#Cal(2**300)
#Cal(2**300 - 1)
#Cal(2**300 - 2)
#Cal(2**300 - 3)
#Cal(2**309)
#Cal(2**309 + 2 ** 5 - 1)