# prev = itr.__next__() # for item in itr: # yield prev # prev = item # # meiniterator=notlast(test1) # # for i in meiniterator: # print(i) from collections import defaultdict, deque from Day2 import getPuzzleinput # Edges E = defaultdict(list) # In-degree D = defaultdict(int) Inp = getPuzzleinput(7) for line in Inp: words = line.split() x = words[1] y = words[7] E[x].append(y) D[y] += 1 for k in E: E[k] = sorted(E[k]) # time t = 0 # Events EV = [] # Work queue
else: pass index += 1 endlen = len(polymer) if startlen == endlen: reactive = False return polymer def badunit(reducedpolymer): char = 'abcdefghijklmnopqrstuvwxyz' polymerlength = {} for c in char: reduced = [i for i in reducedpolymer if i.casefold() != c] #reduced=re.sub('c','',reducedpolymer) shortpoly = reaction(reduced) polymerlength[c] = len(shortpoly) return polymerlength if __name__ == "__main__": string = getPuzzleinput(5) string = [i for i in string[0]] #string=['a','a','b','c','C','c','d','D','B','A','x'] # polymerraw=getPuzzleinput(5)[0] # polymer=[i for i in polymerraw] # # twoiters=customiter(polymer) reaction(string) bestdelete = badunit(string)
elif gridndist[i][3]>d: gridndist[i][3]=d gridndist[i][2]=p elif gridndist[i][3]==d: gridndist[i][2] = 99 else: pass infinite=[] for i in range(len(gridndist)): if (gridndist[i][0]==0 or gridndist[i][1]==0) and (gridndist[i][2] not in infinite): infinite.append(gridndist[i][2]) for i in infinite: try: del points[int(i)] except: pass pointsum=[] for p in points: pointsum.append(np.count_nonzero(gridndist[:,2]==p)) return gridndist,infinite,pointsum if __name__=="__main__": coordinates=getPuzzleinput(6) points,x,y=borders(coordinates) grid=meshgrid(x,y) #gd,inf,res=manhatten(grid,points) gd,res=points1000(grid,points)
minutes = np.zeros(60) active = 0 for stamp, stampon in customiter(ids): if str(sleepmaster) in stamp: active = 1 elif 'falls' in stamp and active == 1: for i in range(int(stamp[15:17]), int(stampon[15:17])): minutes[i] += 1 elif 'wakes' in stamp and active == 1: continue else: active = 0 continue return minutes if __name__ == "__main__": ids = getPuzzleinput(4) sortbytime(ids) Numbergurads, sleepmaster = sumsleeptime(ids) sleepsum = mostminute(sleepmaster) result = sleepmaster * np.argmax(sleepsum) Guradminutes = [{ i: (np.where(mostminute(i) == np.max(mostminute(i))), np.max(mostminute(i))) } for i, k in Numbergurads.items()] # for i,k in Numbergurads.items(): # mostminute(i) # Guard