From 72daf18fe4c1191cda23a0b2aed4d81858927ffe Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Fri, 8 Dec 2023 16:56:35 +0100 Subject: [PATCH] Working on 2023-12-08 p2 --- 2023/day8/part2.py | 33 +- 2023/day8/r/input.txt | 768 ++++++++++++++++++++++++++++++++++++++++++ 2023/day8/r/part2.py | 63 ++++ 3 files changed, 857 insertions(+), 7 deletions(-) create mode 100644 2023/day8/r/input.txt create mode 100644 2023/day8/r/part2.py diff --git a/2023/day8/part2.py b/2023/day8/part2.py index 6af6c80..fed123e 100644 --- a/2023/day8/part2.py +++ b/2023/day8/part2.py @@ -10,9 +10,9 @@ input_f = sys.argv[1] def pp(x): for i in x: - for j in i: - print(j) - print() + print(nodes[i].value,nodes[i].left,nodes[i].right) + + d, *maps = open(input_f).read().split('\n') @@ -51,11 +51,30 @@ try: except: print() +def done(x): + print(x) + for i in x: + if not i.endswith('Z'): + return False + return True -current = {} +pp(nodes) + +current = [] for i in nodes: if i.endswith('A'): - current[i] = i - -#while not current.endswith('Z'): + current.append(i) +count = 0 +steps = 0 +while not done(current): + steps += 1 + for i in range(len(current)): + if d[count%len(d)] == 'L': + #print("Going left from " + str(current[i]) + " to " + str(nodes[current[i]].left)) + current[i] = nodes[current[i]].left + else: + #print("Going right from " + str(current[i]) + " to " + str(nodes[current[i]].right)) + current[i] = nodes[current[i]].right + count += 1 +print(steps) diff --git a/2023/day8/r/input.txt b/2023/day8/r/input.txt new file mode 100644 index 0000000..cc89eb0 --- /dev/null +++ b/2023/day8/r/input.txt @@ -0,0 +1,768 @@ +LRRRLRRLRLLRLRRLRLRLLRRRLRLRRRLRRRLRLRLRRLRLRRRLRRLLRRLLLRRLRRLRRRLRLRRRLRRLRRRLRRRLRRLRLLRRRLRLRRLRLRLRRRLRRLLRRRLLRRLRLRRLRRRLLLRRRLLRLLRRLRRRLRLRLRRLLLRRRLLRRLLLRLRLRRLLRLLRRLLLRRLLRRRLRLRRRLRLLRRRLRRRLRLRLRRRLRLRRRLRRRLRRRLLRLRLRLRRLRLRRRLRLRLLRRLRRLRRLRRRLRRRLRLLRLLLRRLRLRRRR + +HGK = (LRV, NBJ) +MCT = (PKH, PBF) +FJD = (PGR, CJB) +CQL = (XNN, GCT) +PBV = (QSS, PDK) +MPX = (DHN, NCX) +KKH = (HBR, MXL) +BLM = (DHN, NCX) +TTF = (FRT, CHK) +JDT = (SSQ, KHX) +KKR = (STS, RVK) +KRM = (JXX, LQG) +TTD = (SGV, VPF) +KCP = (NPP, CTV) +PTM = (MNN, GTS) +KTP = (GLC, GJH) +FNQ = (NVT, LXV) +TKQ = (DCR, GJX) +LXV = (VCC, CNC) +DVQ = (QHD, TPF) +QRN = (TXV, HFX) +KFH = (XHS, SHB) +QRT = (KQH, FFN) +XKC = (NTC, RMK) +GTH = (NVL, FFK) +MJS = (BLD, SQD) +XQB = (HVK, LVV) +CLV = (XQB, XQS) +HTH = (NSS, BKT) +FMK = (DSS, JMS) +KDF = (VTP, GMR) +VFG = (DLS, TPQ) +RHB = (SMB, JVD) +DPX = (LHH, GNB) +XHC = (RDF, XQN) +MGD = (PKH, PBF) +PTP = (KCT, BJH) +RVV = (FKC, XHC) +BRL = (BJH, KCT) +JJF = (MCK, BCJ) +KGR = (GJM, GJM) +KRF = (FMD, BGJ) +XQN = (DDR, NNX) +TVQ = (XTH, PJL) +HMT = (JNJ, BVS) +NKB = (JXR, FQM) +SFJ = (KFH, CCB) +FMB = (NKB, DGT) +VKD = (FMD, BGJ) +PJR = (BTS, LNN) +RJG = (DGK, BRS) +LSZ = (BDS, RXJ) +CTV = (KFV, JVF) +TGP = (CTJ, FBQ) +HVX = (JMR, RQT) +RVK = (CTC, RDJ) +KGS = (KMM, JPV) +SCC = (QCG, TCS) +HBR = (TGG, KBG) +PND = (BMC, HSK) +FQD = (PTD, NGM) +XGH = (KKS, HHC) +NJJ = (RHC, SFQ) +SNF = (FXJ, BSR) +DDR = (TSQ, PJR) +VRV = (NMJ, JBJ) +FFL = (NRD, BPD) +NMJ = (LTR, RQQ) +FSK = (KVQ, JXS) +MLF = (HGD, XHZ) +RQQ = (JGF, GGS) +KSN = (HGL, HVX) +VCR = (QNN, LLB) +PKH = (XSR, XDF) +DFL = (FFK, NVL) +LPQ = (FKS, PGM) +DQR = (JQV, FDP) +SSQ = (QPT, QPT) +JNC = (SPK, JPG) +SFQ = (BPG, NSQ) +NCD = (TJB, GBP) +CTJ = (KTF, DQF) +VPC = (VFG, QVQ) +SQD = (XQC, PHJ) +XKH = (MJS, SNH) +VDS = (FKD, PKD) +GFF = (JCF, HBS) +FKD = (MCM, LKD) +XDT = (NTC, RMK) +GRK = (RFQ, CSF) +PKN = (NGK, FLG) +QHD = (FSJ, FSJ) +GHS = (HTD, KLJ) +JGR = (RRD, XVQ) +XVC = (KGS, CNG) +XFH = (RTB, DDK) +CJS = (KKR, BNX) +KLJ = (NMN, LQK) +PJB = (GTH, DFL) +NPT = (JRJ, TVT) +FJX = (GXQ, VCG) +QBH = (QCL, VCB) +SXT = (MKJ, BLC) +GTR = (CDG, BFT) +KDJ = (GVL, KTD) +NTC = (RJP, SVQ) +DTP = (BSR, FXJ) +FDN = (JHK, VNQ) +BKL = (SBV, XKD) +VCX = (JQV, FDP) +LQG = (DKP, HTH) +MCM = (RSJ, PXH) +VHT = (CVK, MBQ) +XQS = (LVV, HVK) +CPG = (VFR, LVN) +QVQ = (TPQ, DLS) +VSH = (JNJ, BVS) +CFB = (FXD, FQK) +BGF = (TTJ, GNT) +MBB = (MKH, TKK) +SBV = (MQQ, DSG) +JBR = (NDX, MBB) +SMT = (KKS, HHC) +CSF = (QHG, VXS) +SFN = (LRD, NJJ) +GGS = (JLD, LPJ) +CHK = (QGS, RQZ) +RNH = (BCJ, MCK) +GJX = (XKQ, XTF) +TVB = (HGK, LJB) +SGV = (NNQ, LTF) +JHR = (XMH, SJB) +NBN = (BBH, PJQ) +BPV = (MRP, MRP) +PCH = (LFV, JCP) +KPR = (TDB, RVV) +KKT = (SNM, QBH) +DPS = (QPK, VSP) +LXM = (RNH, JJF) +TRK = (XVM, RHX) +TLT = (QQT, SXT) +DDB = (PML, MXS) +DSG = (BVH, QML) +MHD = (PMV, GHH) +XVQ = (MFC, JBH) +TTJ = (PJN, CQD) +XTG = (VBD, GFF) +VJF = (TVQ, NRP) +NSS = (HHN, FXT) +XSR = (CQL, RRX) +SPK = (BBP, LMK) +RSB = (KKR, BNX) +XNL = (NJJ, LRD) +SBH = (TVQ, NRP) +JXR = (NJK, CGS) +DGX = (VPL, TRK) +KTD = (KSP, TGB) +CBP = (LXM, TRM) +DCM = (FTX, FNC) +LMP = (NRX, JQL) +QNP = (FGF, QBT) +GJT = (TFD, FVN) +NPP = (KFV, JVF) +SVG = (DSS, JMS) +KBG = (KKG, PHN) +RDJ = (GJV, HBN) +NQS = (SNM, QBH) +GHR = (DVK, BCH) +LBX = (BNR, KDJ) +SCJ = (MPS, RCR) +HHM = (FXP, LTB) +LCV = (BFT, CDG) +LKS = (MRS, GSH) +JQL = (GBT, STL) +LHK = (VVP, LDT) +FLX = (TKQ, DCL) +VFR = (HDF, VSV) +XQK = (FJD, MCG) +JNF = (VDF, XJB) +GXL = (FQD, QFJ) +GBT = (CLG, KBH) +VFV = (SSL, FMM) +RHX = (LKS, BSD) +LRD = (RHC, SFQ) +TKK = (GJT, NFV) +XTF = (GPQ, XVX) +DQH = (KSN, GNR) +TPQ = (MPB, DSJ) +HTS = (XVQ, RRD) +LFN = (KVX, TTD) +NBQ = (JCH, TTM) +FMT = (DDB, NRN) +KTF = (FLX, DRP) +NRP = (XTH, PJL) +RFQ = (QHG, VXS) +CRG = (BPJ, LRF) +NRN = (PML, MXS) +MXF = (CTV, NPP) +BBV = (XXR, KQB) +LVN = (VSV, HDF) +PTK = (MVK, MVK) +NHM = (TXP, DLL) +NTK = (FGC, CGG) +LRF = (NRM, VHT) +XGG = (SSN, PBV) +ZZZ = (HRP, SRS) +DQF = (DRP, FLX) +NTT = (RCT, VBL) +HDH = (MGD, MCT) +CVK = (DXG, DCM) +KHX = (QPT, FHZ) +GNR = (HVX, HGL) +KVQ = (CBP, VMP) +JFC = (VFV, KRP) +FLG = (QTT, VKR) +VSP = (JXH, PKN) +HQN = (GJH, GLC) +GNV = (FXD, FQK) +BCJ = (MRT, GSD) +KKG = (DDC, XMN) +TLM = (JJM, QGK) +VMP = (LXM, TRM) +MPB = (NGN, JTD) +NFV = (TFD, FVN) +FVN = (DCP, PXL) +NMQ = (VNK, DGX) +NJB = (VXB, SFF) +NPD = (NKB, DGT) +JJM = (BBV, GPV) +PQT = (XQK, KBT) +PJL = (NQS, KKT) +FTX = (PPL, RGJ) +JCH = (DPP, GDB) +SCN = (TKM, CLV) +MKJ = (JFQ, FMT) +JGN = (QBS, MFB) +GJH = (SLD, LQT) +GVL = (TGB, KSP) +NBM = (QRN, CGF) +XXR = (FMK, SVG) +FQK = (QBN, NTK) +BLX = (BMC, HSK) +RCR = (JJR, DPX) +TTG = (CTJ, FBQ) +SSL = (KHQ, XFH) +PKD = (LKD, MCM) +RJH = (XKH, JCR) +VPF = (NNQ, LTF) +TJB = (TXQ, JFC) +XHZ = (NHM, PFM) +XTL = (RXJ, BDS) +HQS = (KPR, GLQ) +RRD = (MFC, JBH) +FLN = (VCH, BGT) +VBD = (HBS, JCF) +TLR = (XTR, FSK) +CHD = (FXP, LTB) +HHN = (CNB, MDX) +RJP = (TLM, NNT) +HKC = (RVN, JKR) +SJL = (CHD, HHM) +FDP = (TLR, SRP) +VPK = (MRP, RND) +VQP = (BHF, MVH) +XMN = (GRK, NLN) +MVK = (MLS, MLS) +GXM = (GJF, CRG) +KFB = (HTD, KLJ) +GFR = (XNL, SFN) +BCL = (SRS, HRP) +NLT = (SNT, VMJ) +BRQ = (FQD, QFJ) +VPL = (XVM, RHX) +VJN = (SJB, XMH) +GHH = (NSG, HVR) +BBP = (XGH, SMT) +DCB = (MVS, NRC) +DGK = (FQP, KDF) +BLC = (JFQ, FMT) +TCS = (PVK, HSJ) +PPL = (RSF, FSX) +QTT = (KHG, QLF) +PML = (NCQ, VRK) +LLB = (SGJ, VHX) +VXK = (FKD, PKD) +FSX = (CJS, RSB) +KKS = (SJL, SFR) +JLD = (RXB, RJL) +VGG = (XTL, LSZ) +BLG = (KFH, CCB) +TPF = (FSJ, GDP) +JFQ = (DDB, NRN) +RDF = (NNX, DDR) +HGL = (RQT, JMR) +KQB = (SVG, FMK) +RMM = (JHK, VNQ) +BCH = (VPC, GXH) +MCG = (PGR, CJB) +JBT = (PLF, VQP) +NSQ = (PTK, TNS) +RVN = (CMP, DBF) +XGK = (VCH, BGT) +BNR = (KTD, GVL) +QML = (QQV, VFJ) +KSD = (SFB, GGM) +PDK = (JJH, BNH) +KBH = (NTT, BVQ) +MSA = (PFM, NHM) +JRJ = (KXT, SFV) +AAA = (SRS, HRP) +NRD = (NLM, FXR) +QCL = (JTT, LBX) +CTC = (HBN, GJV) +DDK = (LCV, GTR) +PBF = (XSR, XDF) +TKM = (XQS, XQB) +SNM = (VCB, QCL) +JCC = (LQQ, RFC) +GSN = (VXB, SFF) +CNG = (JPV, KMM) +VMJ = (GVC, HGN) +CXT = (LDT, VVP) +CLG = (NTT, BVQ) +HHC = (SFR, SJL) +VTP = (SNF, DTP) +PKA = (STR, TVR) +MFB = (NJB, GSN) +NNX = (TSQ, PJR) +LCP = (HGK, LJB) +MQQ = (BVH, QML) +MXL = (TGG, KBG) +FHZ = (TVR, STR) +LQK = (SXB, LHF) +QNM = (RXR, BXF) +LNN = (SKN, BXL) +HSJ = (PJB, VVJ) +SHS = (SPK, JPG) +VKR = (QLF, KHG) +VMC = (CRG, GJF) +XHS = (KQK, FNQ) +BKT = (HHN, FXT) +NCJ = (PMV, GHH) +RQL = (NBF, CXB) +MNG = (CCT, SRB) +MQB = (CKV, XTG) +PGR = (XJS, SCN) +JCP = (VJS, FJX) +TFD = (PXL, DCP) +XTH = (NQS, KKT) +JBH = (GXM, VMC) +SLD = (BBC, RQH) +BBH = (XCD, HQS) +HRP = (VDJ, NCD) +CCT = (JNC, SHS) +VNK = (VPL, TRK) +QPT = (STR, TVR) +MJC = (FLN, XGK) +TBK = (GJM, NCH) +JCR = (SNH, MJS) +TBC = (KVX, TTD) +HDF = (GFR, TMR) +DJV = (SFJ, BLG) +VDJ = (GBP, TJB) +FKS = (KKH, FGH) +TXV = (NCJ, MHD) +FGH = (MXL, HBR) +RSJ = (CPG, RFT) +MVS = (HMT, VSH) +QBN = (CGG, FGC) +GSH = (HTS, JGR) +FBQ = (DQF, KTF) +SFR = (CHD, HHM) +PHN = (XMN, DDC) +KRS = (GNV, CFB) +QSS = (JJH, BNH) +BXL = (NJG, HKC) +RRX = (GCT, XNN) +KCT = (SLM, CCK) +BVQ = (RCT, VBL) +NMN = (LHF, SXB) +RQV = (SBV, XKD) +JJR = (LHH, GNB) +VCC = (BPV, VPK) +TPB = (MJC, XBQ) +SSN = (QSS, PDK) +GXH = (VFG, QVQ) +MRT = (VJN, JHR) +CRL = (VDF, XJB) +RFC = (LMX, PVR) +FGC = (CKT, SVS) +XKS = (BGV, MPT) +CCB = (XHS, SHB) +QGK = (BBV, GPV) +FTP = (SSQ, SSQ) +BSB = (MLS, HKM) +SKN = (HKC, NJG) +MNL = (TBC, LFN) +MRP = (QLX, QLX) +BSD = (MRS, GSH) +GXQ = (TTG, TGP) +FXD = (QBN, NTK) +GDP = (QJV, LXZ) +PJN = (DKM, NLT) +BNH = (KGR, TBK) +LHH = (RBC, HFK) +TDB = (XHC, FKC) +PXH = (CPG, RFT) +DRG = (JCR, XKH) +VXB = (NQQ, FLR) +JBJ = (RQQ, LTR) +JCF = (LPQ, JPC) +SJR = (QNN, LLB) +CGS = (HQB, FGG) +GLN = (KFB, GHS) +XKD = (MQQ, DSG) +HBN = (KSD, TNM) +XHB = (HQN, KTP) +FVJ = (GNV, CFB) +LJB = (NBJ, LRV) +NVL = (XVC, FBC) +SXB = (KRS, FVJ) +RHC = (BPG, NSQ) +LHF = (KRS, FVJ) +STR = (BNF, GLN) +MCK = (GSD, MRT) +RBC = (BRL, PTP) +MRS = (HTS, JGR) +SFF = (FLR, NQQ) +SRP = (FSK, XTR) +XQC = (BRQ, GXL) +BTS = (BXL, SKN) +MFC = (GXM, VMC) +BGT = (NMD, PCH) +RGJ = (RSF, FSX) +FPN = (SXT, QQT) +BNF = (KFB, GHS) +VVP = (XGJ, GPD) +CGG = (CKT, SVS) +XVX = (FMB, NPD) +DDC = (GRK, NLN) +JXX = (DKP, HTH) +JKR = (CMP, DBF) +SGJ = (KVS, CGD) +TRM = (RNH, JJF) +GNB = (HFK, RBC) +CGK = (DCB, SBB) +MDN = (RFC, LQQ) +XJS = (CLV, TKM) +LTF = (PTM, KRX) +NCH = (GMX, VGG) +NSG = (DRG, RJH) +RXJ = (LCP, TVB) +QLF = (JJQ, FSN) +TSQ = (BTS, LNN) +FNC = (RGJ, PPL) +RXB = (PQT, QDN) +SNH = (BLD, SQD) +PJQ = (XCD, HQS) +DHN = (BGF, XXN) +QNN = (SGJ, VHX) +BRS = (FQP, KDF) +DRP = (DCL, TKQ) +KMM = (BKX, CGK) +MLS = (BCL, BCL) +QQT = (BLC, MKJ) +FFK = (FBC, XVC) +BPG = (PTK, TNS) +LTB = (XFC, KRM) +XTR = (JXS, KVQ) +PDF = (DVK, BCH) +KVX = (SGV, VPF) +DPP = (JVB, GKC) +VVJ = (GTH, DFL) +KVS = (BQG, KCQ) +LFV = (VJS, FJX) +TNG = (PJQ, BBH) +NRM = (MBQ, CVK) +CMP = (VKD, KRF) +GTS = (BPT, TPB) +BHF = (DJV, SSD) +JNJ = (RGX, VRB) +DKM = (VMJ, SNT) +TSM = (QBS, MFB) +BKX = (SBB, DCB) +FBC = (CNG, KGS) +TNM = (SFB, GGM) +BQG = (TSM, JGN) +TMR = (XNL, SFN) +NGK = (VKR, QTT) +GDB = (GKC, JVB) +TXP = (FPN, TLT) +NRX = (STL, GBT) +BPT = (XBQ, MJC) +HGN = (JPS, QLM) +QLM = (SCJ, RNV) +XCT = (DGX, VNK) +HTD = (LQK, NMN) +TLQ = (JRJ, TVT) +GJM = (GMX, GMX) +KFV = (GSS, TPM) +KXT = (RJG, MGB) +GSD = (JHR, VJN) +NVT = (VCC, CNC) +KQH = (XCT, NMQ) +HVR = (DRG, RJH) +LMK = (XGH, SMT) +JTD = (GSL, MQB) +PMV = (HVR, NSG) +JPG = (LMK, BBP) +RMK = (RJP, SVQ) +LMX = (XLJ, PXQ) +MGB = (DGK, BRS) +PTD = (HDH, THF) +FQM = (CGS, NJK) +GSS = (BLX, PND) +GJF = (BPJ, LRF) +DLL = (TLT, FPN) +NJG = (JKR, RVN) +JPC = (PGM, FKS) +SRS = (NCD, VDJ) +XVM = (LKS, BSD) +KRX = (GTS, MNN) +RQT = (BKL, RQV) +BLD = (PHJ, XQC) +LKD = (PXH, RSJ) +NJN = (VDT, NBM) +GPV = (KQB, XXR) +VDF = (VXK, VDS) +CKT = (DQR, VCX) +SLF = (LGK, XGG) +PSL = (XDT, XKC) +NNQ = (PTM, KRX) +TVR = (GLN, BNF) +PVK = (PJB, VVJ) +DXG = (FTX, FNC) +NBJ = (DQH, FDJ) +CXB = (XSQ, QNP) +NBF = (QNP, XSQ) +MBQ = (DCM, DXG) +BBX = (JQL, NRX) +XBQ = (XGK, FLN) +GKC = (MLD, FFL) +GSL = (CKV, XTG) +SBB = (NRC, MVS) +QJV = (KQP, XHB) +FMM = (XFH, KHQ) +TXQ = (KRP, VFV) +DCR = (XKQ, XTF) +BJH = (CCK, SLM) +RGX = (QRV, QRV) +SFV = (RJG, MGB) +GFQ = (PLF, VQP) +BGJ = (TCQ, SLF) +LTR = (GGS, JGF) +JVD = (QVS, XKS) +HKM = (BCL, ZZZ) +GBP = (JFC, TXQ) +VBL = (BLM, MPX) +GRV = (QPK, VSP) +BBC = (KCP, MXF) +BVH = (VFJ, QQV) +FDJ = (KSN, GNR) +KCQ = (TSM, JGN) +NNT = (QGK, JJM) +BVS = (RGX, VRB) +XGJ = (NPT, TLQ) +JPV = (BKX, CGK) +NCX = (XXN, BGF) +SFB = (FTP, FTP) +QQV = (SJR, VCR) +KBT = (FJD, MCG) +GNT = (CQD, PJN) +NLM = (QRT, XNT) +CJB = (XJS, SCN) +CCK = (NBN, TNG) +XLJ = (CRL, JNF) +HVK = (MNG, CVP) +GLQ = (RVV, TDB) +JJH = (KGR, TBK) +MVH = (SSD, DJV) +PLF = (MVH, BHF) +HQB = (CKL, DVQ) +HBS = (LPQ, JPC) +NRC = (HMT, VSH) +CGD = (KCQ, BQG) +BGV = (RMM, FDN) +TTM = (DPP, GDB) +DKP = (NSS, BKT) +MKH = (NFV, GJT) +RQZ = (GHR, PDF) +XMH = (DPS, GRV) +JMS = (SBH, VJF) +DVK = (VPC, GXH) +VRB = (QRV, TTF) +XSQ = (FGF, QBT) +DDQ = (NJN, KQV) +HFK = (BRL, PTP) +NBA = (RXJ, BDS) +SLM = (NBN, TNG) +NDX = (TKK, MKH) +VFJ = (VCR, SJR) +XNN = (TML, RGD) +KQV = (NBM, VDT) +BDS = (LCP, TVB) +JVF = (TPM, GSS) +FVH = (CGL, NBQ) +CNB = (GFQ, JBT) +RHA = (PDF, GHR) +QFJ = (NGM, PTD) +JXS = (VMP, CBP) +XKQ = (GPQ, XVX) +FXJ = (XPP, JBR) +RFT = (VFR, LVN) +DSS = (VJF, SBH) +JPS = (SCJ, RNV) +XDF = (CQL, RRX) +FFN = (NMQ, XCT) +VJS = (VCG, GXQ) +TJS = (XDT, XKC) +SMB = (QVS, XKS) +FSJ = (QJV, QJV) +QRV = (FRT, FRT) +TML = (CXT, LHK) +CQD = (NLT, DKM) +SHB = (KQK, FNQ) +PGM = (KKH, FGH) +RSF = (CJS, RSB) +LXZ = (XHB, KQP) +KHG = (JJQ, FSN) +CGF = (HFX, TXV) +BFT = (PVS, DDQ) +NJK = (HQB, FGG) +TCQ = (XGG, LGK) +SNT = (HGN, GVC) +VCG = (TGP, TTG) +VSV = (GFR, TMR) +THF = (MGD, MCT) +TVT = (SFV, KXT) +LQQ = (PVR, LMX) +CKL = (QHD, QHD) +GPD = (NPT, TLQ) +DSJ = (NGN, JTD) +CVP = (SRB, CCT) +VNQ = (GQL, FVH) +MDX = (GFQ, JBT) +PVR = (PXQ, XLJ) +MXS = (VRK, NCQ) +DBF = (KRF, VKD) +CDA = (KQP, XHB) +XCD = (KPR, GLQ) +GJV = (KSD, TNM) +JMR = (BKL, RQV) +CKV = (GFF, VBD) +GMR = (DTP, SNF) +VCH = (NMD, PCH) +JJQ = (RQL, JVX) +SSD = (BLG, SFJ) +NQQ = (BBX, LMP) +PVS = (KQV, NJN) +BSR = (JBR, XPP) +SVQ = (NNT, TLM) +HSK = (HJM, MNL) +RQH = (MXF, KCP) +FXP = (XFC, KRM) +BPD = (FXR, NLM) +FQP = (VTP, GMR) +HJM = (TBC, LFN) +KQP = (KTP, HQN) +TPM = (PND, BLX) +DCP = (MDN, JCC) +LPJ = (RXB, RJL) +QBT = (RHB, VBG) +KRP = (FMM, SSL) +NCQ = (VRV, GFS) +FLR = (BBX, LMP) +VRK = (GFS, VRV) +RNV = (RCR, MPS) +XXN = (GNT, TTJ) +DLS = (DSJ, MPB) +TGG = (KKG, PHN) +CNC = (BPV, VPK) +CDG = (DDQ, PVS) +JXH = (NGK, FLG) +BXF = (CJN, SCC) +FMD = (SLF, TCQ) +JQV = (TLR, SRP) +RGD = (CXT, LHK) +QGS = (PDF, GHR) +RTB = (LCV, GTR) +RXR = (SCC, CJN) +FKC = (XQN, RDF) +RJL = (PQT, QDN) +DGT = (FQM, JXR) +GMX = (XTL, XTL) +KHQ = (RTB, DDK) +GCT = (TML, RGD) +SJB = (GRV, DPS) +SVS = (DQR, VCX) +NLN = (RFQ, CSF) +NGN = (GSL, MQB) +PFM = (TXP, DLL) +VCB = (JTT, LBX) +QBS = (NJB, GSN) +XPP = (NDX, MBB) +QCG = (HSJ, PVK) +LGK = (SSN, PBV) +NGM = (HDH, THF) +BMC = (HJM, MNL) +GGM = (FTP, JDT) +PXL = (MDN, JCC) +PHJ = (BRQ, GXL) +QVS = (MPT, BGV) +GQL = (NBQ, CGL) +GLC = (SLD, LQT) +MNN = (TPB, BPT) +TGB = (VHM, QNM) +MPS = (DPX, JJR) +TNS = (MVK, BSB) +QLX = (HGD, HGD) +JHK = (FVH, GQL) +CGL = (JCH, TTM) +FGF = (VBG, RHB) +CJN = (TCS, QCG) +FSN = (RQL, JVX) +XNT = (KQH, FFN) +GVC = (JPS, QLM) +LDT = (XGJ, GPD) +LQT = (RQH, BBC) +VHX = (KVS, CGD) +PXQ = (JNF, CRL) +FGG = (CKL, DVQ) +STL = (KBH, CLG) +FRT = (QGS, QGS) +RCT = (BLM, MPX) +VXS = (TJS, PSL) +FXT = (MDX, CNB) +KQK = (LXV, NVT) +QDN = (KBT, XQK) +NMD = (JCP, LFV) +GPQ = (FMB, NPD) +QPK = (PKN, JXH) +STS = (CTC, RDJ) +XJB = (VDS, VXK) +BPJ = (NRM, VHT) +GFS = (JBJ, NMJ) +HFX = (MHD, NCJ) +QHG = (TJS, PSL) +FXR = (QRT, XNT) +JTT = (KDJ, BNR) +VHM = (RXR, BXF) +KSP = (VHM, QNM) +JVB = (MLD, FFL) +XFC = (LQG, JXX) +VBG = (JVD, SMB) +JVX = (NBF, CXB) +BNX = (STS, RVK) +VDT = (QRN, CGF) +MPT = (RMM, FDN) +HGD = (PFM, NHM) +SRB = (SHS, JNC) +MLD = (BPD, NRD) +DCL = (DCR, GJX) +LRV = (FDJ, DQH) +RND = (QLX, MLF) +LVV = (CVP, MNG) +JGF = (LPJ, JLD) diff --git a/2023/day8/r/part2.py b/2023/day8/r/part2.py new file mode 100644 index 0000000..6bbbd2a --- /dev/null +++ b/2023/day8/r/part2.py @@ -0,0 +1,63 @@ +# NAIVE, brute force solution, don't use if you want to be done in any reasonable amt of time +class Node(): + def __init__(self, val, left, right): + self.val = val + self.left = left + self.right = right + +def isDone(ls): + for elt in ls: + if not elt.endswith("Z"): + return False + + return True + + +def main(): + with open("input.txt", "r") as f: + lines = [l.strip() for l in f.readlines()] + # print(lines) + + nodesDict = {} + + n = Node(1, 2, 3) + + directions = lines[0] + + for l in lines[2:]: + # build nodes + val = l.split("=")[0].strip() # AAA = (BBB, CCC) + dirs = l.split("=")[1].replace(")", "").replace("(", "").split(", ") + left = dirs[0].strip() + right = dirs[1].strip() + + n = Node(val, left, right) + nodesDict[val] = n + + # print(nodes) + + # curr = "AAA" + totalSteps = 0 + idx = 0 + + nodes = [n for n in nodesDict if n.endswith("A")] + + while not isDone(nodes): + # do directions again and again + totalSteps += 1 + + for i in range(len(nodes)): + direction = directions[idx] + if direction == "L": + nodes[i] = nodesDict[nodes[i]].left + else: + nodes[i] = nodesDict[nodes[i]].right + + idx += 1 + idx %= len(directions) + + print(totalSteps) + + +if __name__ == "__main__": + main() \ No newline at end of file