Compare commits
2 Commits
584618a349
...
e28632c743
Author | SHA1 | Date | |
---|---|---|---|
|
e28632c743 | ||
|
ca9f84df58 |
1000
2021/3/data
Normal file
1000
2021/3/data
Normal file
File diff suppressed because it is too large
Load Diff
48
2021/3/main.py
Normal file
48
2021/3/main.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
bits = []
|
||||||
|
|
||||||
|
gamma = 0
|
||||||
|
epsilon = 0
|
||||||
|
|
||||||
|
gamma_str = ''
|
||||||
|
epsilon_str = ''
|
||||||
|
|
||||||
|
with open('data', 'r') as fp:
|
||||||
|
|
||||||
|
# NOTE(dev): We assume all lines are the same length
|
||||||
|
for i in range(0, len(fp.readline().strip())):
|
||||||
|
bits.append(0)
|
||||||
|
|
||||||
|
# # DEBUG(dev):
|
||||||
|
# test = fp.readline()
|
||||||
|
# for i in range(0, len(test)):
|
||||||
|
# print test[i]
|
||||||
|
|
||||||
|
for line in fp:
|
||||||
|
for i in range(0, len(line.strip())):
|
||||||
|
if(line[i] == '1'):
|
||||||
|
bits[i] = bits[i] + 1
|
||||||
|
else:
|
||||||
|
bits[i] = bits[i] - 1
|
||||||
|
|
||||||
|
for i in range(0, len(bits)):
|
||||||
|
ch = '1'
|
||||||
|
if(bits[i] < 0):
|
||||||
|
ch = '0'
|
||||||
|
gamma_str = gamma_str + ch
|
||||||
|
|
||||||
|
# # DEBUG(dev):
|
||||||
|
# for i in range(1, len(gamma_str)+1):
|
||||||
|
# print gamma_str[-i]
|
||||||
|
|
||||||
|
# NOTE(dev): Have to do (i+1) because we're going backwards, which starts at -1
|
||||||
|
for i in range(0, len(gamma_str)):
|
||||||
|
if(gamma_str[-(i+1)] == '1'):
|
||||||
|
gamma = gamma + pow(2,i)
|
||||||
|
else:
|
||||||
|
epsilon = epsilon + pow(2,i)
|
||||||
|
|
||||||
|
|
||||||
|
# print " bits: ", bits
|
||||||
|
print " gamma: ", gamma
|
||||||
|
print "epsilon: ", epsilon
|
||||||
|
print " POWER: ", gamma * epsilon
|
Loading…
Reference in New Issue
Block a user