Compare commits

..

No commits in common. "cc919d85669c02acb0e22d21c6a39dcb6418fc71" and "519613e1382569839986523d1f1603a25555e66b" have entirely different histories.

2 changed files with 6 additions and 93 deletions

View file

@ -3,14 +3,15 @@
import numpy as np import numpy as np
a = np.array([list(map(int,i)) for i in [list(j) for j in open("08/i").read().strip().split("\n")]]) a = np.array([list(map(int,i)) for i in [list(j) for j in open("08/i").read().strip().split("\n")]])
visible = np.shape(a)[0]*2+(np.shape(a)[1]-2)*2 visible = np.shape(a)[0]*2+(np.shape(a)[1]-2)*2
print(visible)
for y in range(1,np.shape(a)[0]-1): for y in range(1,np.shape(a)[0]-1):
for x in range(1,np.shape(a)[1]-1): for x in range(1,np.shape(a)[1]-1):
# Visible? # Visible?
left = True if np.where(a[y][0:x]>=a[y][x])[0].size<1 else False left = True if len(list(np.where(a[y][0:x]>=a[y][x])[0]))<1 else False
right = True if np.where(a[y][x:] >=a[y][x])[0][1:].size<1 else False right = True if len(list(np.where(a[y][x:] >=a[y][x])[0][1:]))<1 else False
aktiv = True if np.where(a[:,x][0:y]>=a[y,x])[0].size<1 else False aktiv = True if len(list(np.where(a[:,x][0:y]>=a[y,x])[0]))<1 else False
passiv =True if np.where(a[:,x][y:]>=a[y,x])[0][1:].size<1 else False passiv = True if len(list(np.where(a[:,x][y:]>=a[y,x])[0][1:]))<1 else False
if left or right or aktiv or passiv: if left or right or aktiv or passiv:
visible+=1 visible+=1

View file

@ -1,88 +0,0 @@
#!/usr/bin/env python3
import os,time
a="""R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2"""
#a=open("/Users/rasmus/Gits/aoc2022/09/ii").read().strip()
b={"L":-1, "U":1, "R":1, "D":-1}
def mov(cmd,loc):
if cmd[0] in ["U","D"]:
return (loc[0],sum([loc[1],int(cmd[2:])*b[cmd[0]]]))
else:
return (sum([loc[0],int(cmd[2:])*b[cmd[0]]]),loc[1])
logH = [(0,0)]
logT = [(0,0)]
for l in a.split("\n"):
#print("LogT: {}\n".format(logT[-1]))
logH.append(mov(l,logH[-1]))
#print("Diff: {} {}, l {}".format(logH[-1][0]-logT[-1][0],logH[-1][1]-logT[-1][1],l))
#print("LogH: {}".format(logH[-1]))
# If in same column:
if logT[-1][0]==logH[-1][0]:
# Case new head is next to or covering tail:
if logT[-1][1]==logH[-1][1]:
#print("Samme: {} {} {}".format(l,logH[-1],logT[-1]))
logT.append(logT[-1])
continue
elif abs(logT[-1][1]-logH[-1][1])<2:
#print("Tæt: {} {} {}".format(l,logH[-1],logT[-1]))
logT.append(logT[-1])
continue
# If above move to one above, else one below
logT.append((logT[-1][0],logH[-1][1]+1)) if logT[-1][1]>logH[-1][1] else logT.append((logT[-1][0],logH[-1][1]-1))
print("Her")
# If same row:
elif logT[-1][1]==logH[-1][1]:
# Case next to:
if abs(logT[-1][1]-logH[-1][1])<2:
logT.append(logT[-1])
continue
logT.append((logH[-1][0]+1,logT[-1][1])) if logT[-1][0]>logH[-1][0] else logT.append((logH[-1][0]-1,logT[-1][1]))
# If neither:
else:
# Case diagonally next to
if abs(logT[-1][0]-logH[-1][0])<2 and abs(logT[-1][1]-logH[-1][1])<2:
#print("Diagon: {} LogH: {} LogT: {}".format(abs(logT[-1][0]-logH[-1][0]),logH[-1],logT[-1]))
logT.append(logT[-1])
continue
if l[0] in ["U","D"]:
logT.append((logH[-1][0],logH[-1][1]+1)) if logT[-1][1]>logH[-1][1] else logT.append((logH[-1][0],logH[-1][1]-1))
#print("UD")
else:
logT.append((logH[-1][0]+1,logH[-1][1])) if logT[-1][0]>logH[-1][0] else logT.append((logH[-1][0]-1,logH[-1][1]))
print(logH)
print(logT)
print(len(sorted(set(logT))))
exit()
result=[]
for i in range(0,50):
result.append(list(".")*100)
for i in range(0,len(logH)):
result[logT[i][0]][logT[i][1]]="T"
result[logH[i][0]][logH[i][1]]="H"
for b in result:
print("".join(b))
print(f"{i}\n\n")
time.sleep(2)
os.system("clear")
result[logH[i][0]][logH[i][1]]="."
result[logT[i][0]][logT[i][1]]="."
print(len(sorted(set(logT))))