def PartOne(info): info = strToArr(info) info = newlineParse(info) arr = [] tempArr = [] for a in info: if(a == ""): arr.append(tempArr) tempArr = [] else: tempArr.append(a) arr.append(tempArr) info = arr t1 = 0 for i in info: t2 = [] for a in i: for l in a: t2.append(l) t1 += len(list(dict.fromkeys(t2))) t2 = [] return t1
def PartTwo(info): info = strToArr(info) info = newlineParse(info) t1 = 0 t2 = [] for i in info: t2.append(i) for l in t2: d = list(dict.fromkeys(l)) if(len(l) == 1): t1 += len(l[0]) elif(len(d) == 1): t1 += len(d[0]) else: e = [] for q in l: for x in q: e.append(x) de = list(dict.fromkeys(e)) for f in range(len(list(de))): if(e.count(de[f]) == len(l)): t1 += 1 return t1
def PartTwo(info): noParseInfo = info info = strToArr(info) info = newlineParse(info) print(PartOne(noParseInfo)[0]) ids = PartOne(noParseInfo)[1] print(ids) corners = PartOne(noParseInfo)[2] leftUpCorner = "" for i in corners: presentCorners = [] print(i) for j in ids[i]: print(j) presentCorners.append(j[1]) if("top" in presentCorners and "right" in presentCorners): leftUpCorner = i sortedInfo = [] height = getLengthInDir(info, 1, ids, leftUpCorner, "top") width = getLengthInDir(info, 1, ids, leftUpCorner, "right") print(width) for s in range(height): sortedInfo.append([]) print(sortedInfo) stripped = [] for i in info: r = i[1::] ts = [] for j in r[1::][:: -1][1::][:: -1]: s = j[1::][:: -1][1::][:: -1] ts.append(s) stripped.append(ts) info = stripped # for i in info: # for j in i: # print(j) return 0
def PartOne(info): # noParseInfo = info info = strToArr(info) info = newlineParse(info) validRange = {} for i in info[0]: ranges = re.findall(r"\d*\-\d*", i) if (ranges): for r in ranges: o = r.split("-") for i in range(int(o[0]), int(o[1]) + 1): validRange[str(i)] = "" errorRate = 0 for i in info[2][1::]: n = int(i) if (validRange.get(i) is None): errorRate += n return errorRate
def PartOne(info): # noParseInfo = info info = strToArr(info) info = newlineParse(info) edges = [] listedIds = [] for i in info: tileId = re.split(r":| ", i[0])[1] listedIds.append(tileId) top = (i[1], i[1][::-1]) bottom = (i[-1], i[-1][::-1]) l = [] r = [] for j in i[1::]: l.append(j[0]) r.append(j[-1]) left = ("".join(l), "".join(l[::-1])) right = ("".join(r), "".join(r[::-1])) print(tileId) print(right) edges.append({"tid": tileId, "top": top, "bottom": bottom, "left": left, "right": right}) ids = {} objids = ["top", "left", "bottom", "right"] rotdeg = {"top": 0, "left": 90, "bottom": 180, "right": 270} reversedeg = {"0": "top", "1": "left", "2": "bottom", "3": "right"} present = [] present2 = [] for i in edges: ids[i["tid"]] = [] toAppend = [] for j in edges: if(j == i): continue for o in objids: for p in objids: if(i[o][0] == j[p][0]): if(j["tid"] not in toAppend): e = 0 if(o == p and o not in present2): present2.append(o) e = 180 rotdeggeg = rotdeg[p]-rotdeg[o]+e if(rotdeggeg < 0): rotdeggeg = 360 - rotdeggeg d = (int((rotdeggeg/90))+4) % 4 d = int(((d+(rotdeg[p]/90)))+4) % 4 toAppend.append( (j["tid"], reversedeg[str(d)], rotdeg[p]-rotdeg[o])) elif(i[o][0] == j[p][1]): if(j["tid"] not in toAppend): e = 0 if(o == p and o not in present): present.append(o) e = 180 rotdeggeg = rotdeg[o]-rotdeg[p]+e if(rotdeggeg < 0): rotdeggeg = 360 - rotdeggeg d = (int((rotdeggeg/90))+4) % 4 d = int(((d+(rotdeg[p]/90)))+4) % 4 toAppend.append( (j["tid"], reversedeg[str(d)], rotdeg[p]-rotdeg[o]+e)) for t in toAppend: ids[i["tid"]].append(t) corners = [] total = 1 for i in listedIds: if(len(ids[i]) == 2): corners.append(i) total *= int(i) return total, ids, corners
def PartTwo(info): info = strToArr(info) info = newlineParse(info) validRange = {} for i in info[0]: ranges = re.findall(r"\d*\-\d*", i) if (ranges): for r in ranges: o = r.split("-") for i in range(int(o[0]), int(o[1]) + 1): validRange[str(i)] = "" nearbyTickets = [] tempNearbyTickets = [] ticketLength = len(info[1][1::]) for i in enumerate(info[2][1::]): tempNearbyTickets.append(i[1]) if ((i[0] + 1) % ticketLength == 0): nearbyTickets.append(tempNearbyTickets) tempNearbyTickets = [] for i in enumerate(nearbyTickets): for j in i[1]: if (validRange.get(j) is None): nearbyTickets[i[0]] = None continue validTickets = [] for i in nearbyTickets: if (i != None): validTickets.append(i) departureRanges = [] for i in info[0]: ranges = re.findall(r"\d*\-\d*", i) tempValidRange = {} for r in ranges: o = r.split("-") for i in range(int(o[0]), int(o[1]) + 1): tempValidRange[str(i)] = "" departureRanges.append(tempValidRange) validFields = [] for d in departureRanges: valid = [True for m in range(len(departureRanges))] for i in validTickets: for j in enumerate(i): if (d.get(j[1]) is None): valid[j[0]] = False validFields.append(valid) for _ in range(len(info) * 10): for i in enumerate(validFields): if (i[1].count(True) == 1): index = i[1].index(True) for j in enumerate(validFields): if (i[0] == j[0]): continue j[1][index] = False total = 1 for i in validFields[0:6]: t = info[1][1::] total *= int(t[i.index(True)]) return total