Compare commits
No commits in common. "e28632c743b14f95dc0f2a4c98dd242a52c823f1" and "584618a34999bbd342f98ee005e07cbbde2fa4ef" have entirely different histories.
e28632c743
...
584618a349
1000
2021/3/data
1000
2021/3/data
File diff suppressed because it is too large
Load Diff
@ -1,48 +0,0 @@
|
||||
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