153 lines
1.9 KiB
Python
153 lines
1.9 KiB
Python
|
import numpy as np
|
||
|
|
||
|
filename = open("day3_data.txt","r")
|
||
|
x = []
|
||
|
xr = filename.readline().strip()
|
||
|
while xr:
|
||
|
xr = list(map(int,str(xr)))
|
||
|
x.append(xr)
|
||
|
xr = filename.readline().strip()
|
||
|
|
||
|
x = np.array(x)
|
||
|
print(x)
|
||
|
|
||
|
print(x[0][0])
|
||
|
|
||
|
print(x[0,0])
|
||
|
|
||
|
print("---------------")
|
||
|
|
||
|
#for i in range(len(x[:,0])):
|
||
|
# print(x[i][0])
|
||
|
|
||
|
print("------Gamma rate---------")
|
||
|
g=[]
|
||
|
|
||
|
for i in range(len(x[0,:])):
|
||
|
g.append(np.bincount(x[:,i]).argmax())
|
||
|
|
||
|
g = np.array(g)
|
||
|
|
||
|
print("Binary: ",end="")
|
||
|
print(g[:])
|
||
|
|
||
|
print("Decimal: ",end="")
|
||
|
gs=""
|
||
|
gs=''.join(str(n) for n in g)
|
||
|
|
||
|
print(int(gs,2))
|
||
|
|
||
|
|
||
|
print("---------Epsilon rate----------")
|
||
|
|
||
|
e=[]
|
||
|
|
||
|
for i in range(len(x[0,:])):
|
||
|
e.append(np.bincount(x[:,i]).argmin())
|
||
|
|
||
|
e = np.array(e)
|
||
|
|
||
|
print("Binary: ",end=" ")
|
||
|
print(e[:])
|
||
|
|
||
|
print("Decimal: ",end=" ")
|
||
|
es=""
|
||
|
es=''.join(str(n) for n in e)
|
||
|
|
||
|
print(int(es,2))
|
||
|
|
||
|
|
||
|
print("-------power consumption-------")
|
||
|
|
||
|
print("Power Consumption ",end="")
|
||
|
print(str(int(gs,2)*int(es,2)))
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#print(np.array2string(g,precision=2, separator='',suppress_small=True))
|
||
|
|
||
|
|
||
|
|
||
|
#print()
|
||
|
|
||
|
|
||
|
exit()
|
||
|
print(np.base_repr("10110",10))
|
||
|
|
||
|
g1=np.bincount(x[:,0]).argmax()
|
||
|
g2=np.bincount(x[:,1]).argmax()
|
||
|
g3=np.bincount(x[:,2]).argmax()
|
||
|
g4=np.bincount(x[:,3]).argmax()
|
||
|
g5=np.bincount(x[:,4]).argmax()
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
exit()
|
||
|
|
||
|
with open("day3_test.txt", "r") as f:
|
||
|
x = [ j for j in x.split() ]
|
||
|
|
||
|
|
||
|
print(x)
|
||
|
|
||
|
pc=0
|
||
|
g=0
|
||
|
e=0
|
||
|
|
||
|
for i in range(len(x)):
|
||
|
|
||
|
direction=x[i][0]
|
||
|
temp=int(x[i][1])
|
||
|
|
||
|
if(direction=="up"):
|
||
|
#print("up "+ str(temp))
|
||
|
depth-=temp
|
||
|
elif(direction=="down"):
|
||
|
#print("down " + str(temp))
|
||
|
depth+=temp
|
||
|
elif(direction=="forward"):
|
||
|
#print("forward " + str(temp))
|
||
|
horizontal+=temp
|
||
|
else:
|
||
|
print("ERROR")
|
||
|
|
||
|
print("horizontal: "+str(horizontal))
|
||
|
print("depth: " + str(depth))
|
||
|
|
||
|
print("result: " + str(horizontal*depth))
|
||
|
|
||
|
#print(direction + " " + str(temp))
|
||
|
|
||
|
#print(temp,end=" ")
|
||
|
#print("("+str(type(temp))+")",end=" ")
|