From 31004f16a1aaf5f592c8f00ac00c93faab3930b9 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Fri, 8 Dec 2023 23:21:25 +0000 Subject: [PATCH] day8: [python] completed --- day8/data/input | 776 +++++++++++++++++++++++++++++++++++++++++ day8/data/test_input_1 | 9 + day8/data/test_input_2 | 5 + day8/data/test_input_3 | 10 + day8/run.py | 100 ++++++ 5 files changed, 900 insertions(+) create mode 100644 day8/data/input create mode 100644 day8/data/test_input_1 create mode 100644 day8/data/test_input_2 create mode 100644 day8/data/test_input_3 create mode 100755 day8/run.py diff --git a/day8/data/input b/day8/data/input new file mode 100644 index 0000000..e8dae2d --- /dev/null +++ b/day8/data/input @@ -0,0 +1,776 @@ +LLRRRLLRLRRRLLRLRLRLRLRRRLRRLRRLRLLLRRLLRRLRRLRRLRRRLLLRRLRLRRRLRRRLRLRRLRRRLRLRRRLRLRLLLRLRRLRLRRLRRRLRLRRRLRRRLRRRLRRRLRLRRRLRRRLRLLRRLRLRLRRRLRRLRRRLRRRLRRRLRRRLLLLRRLLRLRRLRRLRRRLRRRLLLRRLRRLRLRRLRRRLRRLRLRRRLRLRRLLRLLRRLRLRRRLRRLRRLRLRRLLLRRRLRLRRRLRLRLLRLRLRRRLRLRLRRRLRRLRRLRRRLRRLLRRRR + +VTM = (VPB, NKT) +LHN = (DLF, GQV) +CRN = (TGB, XCM) +TXR = (JQL, JQL) +LJX = (SPR, LLM) +HSH = (SKP, MFC) +JSC = (QPB, VCP) +KKG = (BFT, NBS) +BCB = (GRT, TLB) +GPA = (SDK, MRM) +CNJ = (FDR, GGT) +GQV = (BSJ, DGF) +CNT = (FLM, TVQ) +RLL = (BRB, CRH) +PPN = (KCF, PSJ) +TFL = (GCD, DMF) +KPM = (TKS, CGP) +FBN = (GPF, LCJ) +DQJ = (MHL, VKQ) +NDD = (QLT, PPG) +GNL = (QGD, LTM) +NBG = (XPM, HTV) +LTT = (RLP, NHB) +QHH = (DDD, ZZZ) +DLN = (KNP, KNP) +XMN = (DGV, DNL) +BCL = (FVG, QMH) +GLR = (JDH, RBR) +LXL = (BVC, RSG) +TCV = (JKG, BTF) +HJC = (KTD, JFQ) +DBK = (RCR, CVZ) +FMD = (QGQ, TJX) +JQG = (FHN, HKX) +XFV = (JJM, LBM) +GXQ = (XFV, MVV) +HTT = (THT, CFL) +FTG = (JRP, VGH) +XJF = (FCL, HNF) +MPT = (RDF, NDJ) +FJG = (VPF, LGQ) +CSK = (NSD, MFH) +QJN = (MPT, PLV) +HJP = (VCP, QPB) +KCF = (LVM, XMX) +FPZ = (FMR, GSL) +LRB = (RFF, GQR) +MHN = (TVD, MVF) +FSH = (VPF, LGQ) +GGT = (XJF, RQQ) +RRL = (JTG, TNF) +MPM = (QBD, QHH) +SHG = (JMJ, TLK) +TTD = (DLK, BBJ) +HLF = (JLF, SKB) +XMG = (CGM, RTL) +FFT = (DFJ, RPJ) +FQL = (PTM, LDJ) +NQJ = (CQM, DDL) +VKQ = (TGR, DBC) +RCD = (XPP, FPP) +HPC = (FLM, TVQ) +PBB = (LQR, PQS) +KBS = (BFT, NBS) +HTD = (JMS, HNX) +SKF = (NLJ, NLJ) +GTA = (GSL, FMR) +RSG = (MLL, LJX) +KRB = (PSG, FMD) +XNP = (LFN, XGC) +TVH = (GDG, MNT) +TXM = (JPK, JVQ) +LPB = (CTQ, VQF) +PST = (VPB, NKT) +BSX = (PLS, HQJ) +TKS = (CMC, TFJ) +DCD = (LXR, KTM) +XKR = (BHS, BBT) +JMS = (LDT, JQG) +BVG = (JMQ, BCS) +SPT = (HFN, SPV) +HNF = (NFQ, KPH) +HXG = (VKC, LKM) +DBL = (MDR, VHG) +NVK = (CGQ, SRF) +PLS = (RJN, DVS) +SPR = (XMG, HSS) +FPQ = (VRX, RQX) +LTM = (DBH, KSB) +VRQ = (SXT, KLQ) +XFX = (PFT, NNK) +GFC = (RCH, MFK) +FLK = (DLK, BBJ) +QVN = (LCV, LCV) +HGP = (GMS, MHR) +BVH = (VLQ, CNJ) +BXS = (GQR, RFF) +SKP = (VDS, QPH) +VRM = (TCK, SND) +CGM = (FVK, HGP) +LDT = (FHN, HKX) +BJK = (GFS, PLM) +PVT = (FDX, QHX) +XGC = (TXR, QKJ) +PKF = (NBQ, RCD) +XJB = (RBR, JDH) +GSC = (PTM, LDJ) +SHQ = (KXR, QGK) +TJR = (QGR, NRN) +GQH = (XJB, GLR) +QSM = (MKQ, VRB) +XRF = (NRN, QGR) +PKV = (NQP, JXT) +QNB = (CTL, JVP) +FDX = (DFL, VRQ) +HDS = (QJH, HBF) +NNK = (NDQ, RBL) +RQM = (DQJ, BBQ) +GJG = (QBC, TRD) +NRL = (HTD, SJR) +TKP = (SKF, VDL) +CQM = (TJS, FJF) +KSC = (PFP, DCC) +RSB = (JTQ, HJJ) +DHC = (BQN, SJP) +PFS = (SKP, MFC) +MDP = (LJQ, BML) +CLK = (BJK, QTG) +KST = (CRH, BRB) +MJS = (NDS, TGD) +QBR = (PSG, FMD) +BSB = (PST, VTM) +FPP = (DCD, TGM) +VLF = (LDR, PSP) +NPF = (KBC, PHJ) +TCK = (DFX, RLN) +QNV = (PST, VTM) +JJM = (HMT, DGT) +PTM = (HQV, QLM) +MNS = (JVP, CTL) +KNP = (CPT, CPT) +GGN = (MTG, VVT) +RBT = (MNM, VSQ) +GFH = (VLB, NSK) +HHC = (NGJ, XFT) +QKJ = (JQL, RKB) +XXC = (VJP, HXP) +PSJ = (XMX, LVM) +CFD = (PFL, PPL) +HXD = (BSN, QMC) +HKX = (SSD, CKC) +XPP = (TGM, DCD) +TQB = (FPD, DRT) +PTT = (HHK, HHK) +XRG = (JRP, VGH) +MBN = (KML, KCN) +JDP = (VMS, LCB) +FJF = (STK, GXR) +XQQ = (BST, SPB) +STK = (CKJ, MVM) +LJQ = (DTG, TMF) +DDD = (PBJ, RXK) +FVL = (PXT, NLS) +HRG = (HMV, XTC) +LDN = (JSQ, HQD) +FMJ = (HLP, GXQ) +RQX = (DPD, SNH) +QML = (CCH, PPF) +VGN = (VJP, HXP) +QLH = (FXX, RFB) +GMS = (BVG, SHR) +QCP = (LBC, RBT) +RMS = (LHN, KDR) +RTC = (NDS, TGD) +GBT = (KSJ, GGS) +FNN = (HTH, LXP) +JMQ = (LTX, LKQ) +HMV = (FJS, KCM) +GGM = (XDB, XNP) +NNC = (PBB, NLF) +HSG = (GJG, DSB) +DTG = (LRD, DXH) +TJS = (STK, GXR) +NQB = (RFB, FXX) +BKL = (PDP, XTB) +VQB = (LCV, HPG) +NQP = (CTG, HRG) +TVK = (NQT, QSM) +TJX = (JPH, GRF) +SPB = (MRF, FMJ) +QPH = (XXC, VGN) +TQS = (MPF, MSC) +LQF = (GHS, BQR) +VRB = (CSK, QLG) +NVH = (QXX, TQB) +FPD = (PKV, MFX) +NDB = (JPR, HDS) +HVM = (XRS, SPN) +BSJ = (PHC, FSD) +NPQ = (VBC, HSG) +BXH = (RKS, RPB) +VJP = (HMC, TVX) +NDJ = (FFT, SRP) +SRP = (DFJ, RPJ) +FHQ = (PDP, XTB) +THD = (VMG, DPL) +MRF = (HLP, GXQ) +SND = (DFX, RLN) +BFT = (BVH, BDJ) +MLL = (LLM, SPR) +RKF = (XRQ, STZ) +HGB = (VJQ, MHN) +CBM = (BXH, KMM) +VPD = (HDS, JPR) +RQR = (SMH, KPM) +FVG = (MMM, CLK) +FMP = (VFC, LCC) +QBD = (DDD, DDD) +RGC = (RLL, KST) +HQV = (PKF, TCS) +PLL = (KSJ, GGS) +PPF = (PNT, GFX) +FRN = (LCJ, GPF) +XPM = (TTT, VTP) +BCH = (NFC, FPQ) +KML = (FCB, RMP) +JBM = (VBH, LLG) +VKL = (RMS, SBX) +MMN = (MDR, VHG) +HMG = (PMN, XBV) +BHS = (NPQ, RTT) +XPC = (GGM, KCC) +DGV = (SPT, DNB) +JSB = (DPS, THK) +MND = (KML, KCN) +VCP = (TLD, TVK) +PFX = (RRL, DMX) +SXK = (TVB, PDR) +BML = (TMF, DTG) +XBV = (HXJ, QJB) +DRR = (MSC, MPF) +DCK = (SLD, VRM) +HFP = (LJQ, BML) +RQG = (DDP, TFL) +MRM = (MND, MBN) +PHC = (HHC, GFT) +VGX = (MHN, VJQ) +LMX = (PLL, GBT) +CQF = (FJG, FSH) +MVV = (LBM, JJM) +HSS = (CGM, RTL) +HJK = (HXG, RQF) +CRV = (LCC, VFC) +SHR = (BCS, JMQ) +TDM = (FNR, MSX) +XFS = (LRX, HPP) +TBC = (SKF, VDL) +JXM = (GSL, FMR) +KCC = (XNP, XDB) +LVM = (NJX, GFC) +XRS = (MSL, BSM) +TGV = (LBC, RBT) +SDH = (XPM, HTV) +HGV = (FVL, CSF) +GNH = (SJP, BQN) +TDN = (MNT, GDG) +HJS = (KBC, PHJ) +QGK = (PRK, RSB) +JRN = (FRN, FBN) +TNP = (QVN, VQB) +FXX = (HLF, KPB) +VBH = (QTV, TFR) +XBL = (MSX, FNR) +TRN = (SQR, MQN) +RHP = (JSC, HJP) +JPC = (NNK, PFT) +BSM = (TRN, MCS) +DPD = (DBL, MMN) +DPP = (BSX, NMG) +GFM = (GGN, LLX) +DBC = (SXK, NSL) +KGB = (CBM, DQT) +MCS = (MQN, SQR) +PDR = (NNC, RXP) +MTG = (FGV, LDN) +VGH = (SJH, BRX) +GPF = (QGB, KKM) +PFL = (JPC, XFX) +FFF = (QSR, HMG) +XSS = (PPG, QLT) +LDM = (KNV, BCL) +RMP = (CFD, LHR) +NQT = (VRB, MKQ) +BXM = (FTX, NVK) +CTL = (TKG, RHP) +NBS = (BVH, BDJ) +BVQ = (VPD, NDB) +PGB = (FGQ, KGB) +SLB = (GQH, VSP) +GPV = (JMJ, TLK) +NJX = (RCH, MFK) +LKQ = (JQN, MCR) +BPB = (RFQ, GSP) +FHN = (CKC, SSD) +CKC = (RQM, FCQ) +HTH = (HJC, NTF) +DJP = (NQB, QLH) +TGD = (XPL, KNQ) +CPT = (RCR, RCR) +LLM = (HSS, XMG) +MFC = (QPH, VDS) +VSP = (GLR, XJB) +FMR = (KSC, JVM) +DGF = (FSD, PHC) +KNQ = (XLB, RQR) +CNB = (KRB, QBR) +QHX = (DFL, VRQ) +HBL = (NMN, QJN) +XTC = (FJS, KCM) +LGQ = (LPB, FLQ) +NGJ = (HJK, VTL) +TVX = (MKF, QSN) +GVG = (HRQ, XFS) +QGD = (DBH, KSB) +VPB = (CDD, TNP) +MFK = (BSB, QNV) +SXT = (KDJ, DJP) +GVJ = (GGK, JPT) +HQD = (SXS, CPD) +VRP = (XSQ, KKH) +FNR = (DHC, GNH) +CLT = (BSN, QMC) +CKJ = (VRG, BVQ) +TVQ = (CRV, FMP) +DPS = (XPC, FCP) +SJR = (JMS, HNX) +FLQ = (VQF, CTQ) +HBF = (GVG, XML) +CPD = (RGC, QMS) +BBN = (FPQ, NFC) +MQN = (KBS, KKG) +QTV = (CTB, QJX) +QPJ = (FQL, GSC) +BPD = (CPT, DBK) +FJS = (MNS, QNB) +DDF = (QMD, BPB) +DDL = (FJF, TJS) +QPB = (TLD, TVK) +DFJ = (DJK, FGN) +PFT = (NDQ, RBL) +DQK = (QGD, LTM) +LXR = (LDM, BGD) +FQF = (QJN, NMN) +SLD = (TCK, SND) +RTT = (HSG, VBC) +QSN = (MJQ, KXN) +GGK = (HTG, XNF) +KSB = (VPL, TCV) +BKR = (HSH, PFS) +VRG = (VPD, NDB) +QXX = (DRT, FPD) +LMK = (PTT, XTP) +PQS = (HQR, CQF) +NXS = (TLB, GRT) +VFB = (MFP, CNB) +JVM = (PFP, DCC) +JPK = (XKD, HGV) +KTD = (LXL, QSH) +KKM = (DLN, JXD) +NHB = (NQJ, PFR) +QXK = (KXV, HBV) +CHX = (RRL, DMX) +KKH = (LTT, FHJ) +KDR = (DLF, GQV) +RJD = (RLH, MBJ) +QBC = (VVB, MMD) +MFH = (JRN, RHL) +TLB = (PSN, HNB) +XTB = (FFF, XVV) +SKZ = (VLF, TVV) +DMF = (PDB, JBM) +FMG = (FTX, NVK) +QXP = (DNL, DGV) +GSP = (PXX, PVL) +KXN = (THR, FSN) +GFT = (NGJ, XFT) +QLT = (MDP, HFP) +NBM = (QBD, QBD) +PFP = (BKR, GLT) +NDQ = (KBD, PKH) +JFH = (PTL, QCT) +HRQ = (HPP, LRX) +PNV = (LCB, VMS) +JTG = (NGR, DPP) +THR = (SHQ, CTP) +CBG = (XKR, DRD) +PPL = (XFX, JPC) +RFB = (KPB, HLF) +LCV = (JXM, JXM) +RJN = (SSF, DCK) +NKT = (CDD, TNP) +NTF = (KTD, JFQ) +KLQ = (DJP, KDJ) +QMD = (RFQ, GSP) +TLP = (CNB, MFP) +FGV = (JSQ, HQD) +FGN = (TKH, QKX) +RXK = (TJR, XRF) +PXX = (VJC, FNN) +PHJ = (XRP, PVT) +MVM = (VRG, BVQ) +FSD = (GFT, HHC) +GSL = (JVM, KSC) +VRC = (CFL, THT) +RBL = (KBD, PKH) +RLP = (NQJ, PFR) +BBT = (RTT, NPQ) +MHL = (DBC, TGR) +QGR = (HGB, VGX) +XPL = (XLB, RQR) +SSF = (VRM, SLD) +KRM = (THK, DPS) +MTP = (BCH, BBN) +PDB = (VBH, LLG) +BST = (MRF, FMJ) +DRD = (BHS, BBT) +VHG = (SMJ, QFC) +FTX = (CGQ, SRF) +PNT = (DCT, QPJ) +QJB = (LDX, FPJ) +JKG = (TVH, TDN) +FCQ = (DQJ, BBQ) +HBV = (NBM, MPM) +MDR = (QFC, SMJ) +PTL = (FLK, TTD) +LDR = (HBL, FQF) +NVN = (VFM, VJR) +DQT = (BXH, KMM) +RHL = (FRN, FBN) +MBM = (TLP, VFB) +TVD = (XNJ, VKL) +DNL = (DNB, SPT) +TKH = (XSS, NDD) +JPH = (PVJ, RQG) +VRX = (DPD, SNH) +CVV = (TGB, XCM) +QGB = (DLN, JXD) +SPN = (BSM, MSL) +TGM = (LXR, KTM) +LRD = (XXP, PND) +VMS = (THD, KTF) +MHR = (BVG, SHR) +DMX = (JTG, TNF) +HKJ = (GCF, FXT) +VTP = (DRR, TQS) +VPL = (BTF, JKG) +RCH = (BSB, QNV) +KTM = (LDM, BGD) +QSR = (PMN, XBV) +PXM = (QXP, XMN) +TLK = (CTD, LMX) +BBJ = (MCN, RJD) +RCR = (SDK, MRM) +TVV = (LDR, PSP) +LMQ = (CLT, HXD) +XML = (HRQ, XFS) +RFQ = (PVL, PXX) +QCT = (FLK, TTD) +GXR = (MVM, CKJ) +HPG = (JXM, FPZ) +FCP = (GGM, KCC) +LDX = (PNV, JDP) +MVG = (DQK, GNL) +BNP = (VRC, HTT) +RLH = (QXK, TFF) +DCT = (GSC, FQL) +MFP = (KRB, QBR) +VDA = (CBP, VRP) +THK = (FCP, XPC) +DJK = (QKX, TKH) +VLB = (BXS, LRB) +FCF = (QMD, BPB) +QLM = (TCS, PKF) +BCS = (LKQ, LTX) +MSL = (MCS, TRN) +VQF = (THQ, RBB) +HNB = (QCP, TGV) +SMH = (TKS, CGP) +HMC = (MKF, QSN) +BDJ = (CNJ, VLQ) +NRN = (VGX, HGB) +GSD = (JPK, JVQ) +SXS = (RGC, QMS) +VJR = (CNT, HPC) +RQQ = (FCL, HNF) +FCL = (NFQ, KPH) +JFQ = (QSH, LXL) +TRD = (VVB, MMD) +CTD = (PLL, GBT) +NGR = (BSX, NMG) +MSX = (DHC, GNH) +XNJ = (RMS, SBX) +VHH = (VLB, NSK) +CTG = (XTC, HMV) +NFC = (VRX, RQX) +TNF = (NGR, DPP) +XDB = (LFN, XGC) +PND = (BKL, FHQ) +MFX = (NQP, JXT) +TCS = (RCD, NBQ) +FCJ = (QDF, BNP) +CDQ = (XHV, RSJ) +MBJ = (QXK, TFF) +KPG = (GQH, VSP) +BRX = (NHD, SXL) +HHK = (TVV, VLF) +KCM = (QNB, MNS) +KXR = (RSB, PRK) +HQJ = (RJN, DVS) +XGP = (TQB, QXX) +PCM = (DQN, MKZ) +CDD = (QVN, QVN) +FXT = (DMT, RKF) +FPJ = (JDP, PNV) +DFX = (RSL, HVM) +TFJ = (XBL, TDM) +VFM = (HPC, CNT) +CSF = (PXT, NLS) +MMD = (PGB, PDN) +LHR = (PFL, PPL) +PDP = (FFF, XVV) +GDG = (TKP, TBC) +SNH = (DBL, MMN) +VTL = (HXG, RQF) +KNV = (QMH, FVG) +HMT = (GQT, JFH) +GLT = (PFS, HSH) +QFC = (TXM, GSD) +ZZZ = (RXK, PBJ) +PSG = (QGQ, TJX) +PPG = (HFP, MDP) +RDF = (FFT, SRP) +NSL = (PDR, TVB) +XFT = (HJK, VTL) +GFS = (DDF, FCF) +VPF = (LPB, FLQ) +HTG = (FXN, NVN) +SQR = (KKG, KBS) +SDK = (MND, MBN) +THT = (QML, CTN) +NLS = (GFH, VHH) +KTF = (VMG, DPL) +VDL = (NLJ, LMK) +HFN = (NMQ, LMQ) +QMC = (CFJ, HKJ) +VVL = (KPG, SLB) +DMT = (XRQ, XRQ) +LDJ = (QLM, HQV) +PFR = (DDL, CQM) +HPP = (NXS, BCB) +QLG = (MFH, NSD) +KBC = (PVT, XRP) +FCB = (CFD, LHR) +GCD = (JBM, PDB) +SMR = (GGK, JPT) +CTP = (KXR, QGK) +HXP = (HMC, TVX) +VLQ = (FDR, GGT) +DDP = (GCD, DMF) +JMJ = (CTD, LMX) +CGQ = (KRM, JSB) +XJD = (BCH, BBN) +MNM = (SHG, GPV) +GCF = (DMT, DMT) +DBH = (TCV, VPL) +RKB = (TCX, PCM) +DGT = (JFH, GQT) +JXT = (CTG, HRG) +KPB = (JLF, SKB) +JPT = (XNF, HTG) +NSD = (JRN, RHL) +HTV = (TTT, VTP) +TCX = (DQN, DQN) +MCN = (MBJ, RLH) +CTN = (PPF, CCH) +CTB = (RGB, PXM) +PBJ = (XRF, TJR) +HXJ = (FPJ, LDX) +LLX = (VVT, MTG) +HJJ = (FCJ, NNJ) +CCH = (PNT, GFX) +JVP = (RHP, TKG) +SJH = (NHD, SXL) +RSL = (SPN, XRS) +QMH = (MMM, CLK) +SKB = (FML, MBM) +NBQ = (FPP, XPP) +GQR = (BXM, FMG) +BGV = (DRD, XKR) +HMX = (BQR, GHS) +PVL = (FNN, VJC) +DFL = (SXT, KLQ) +NSK = (BXS, LRB) +MNT = (TKP, TBC) +LTX = (MCR, JQN) +RFF = (BXM, FMG) +NMG = (PLS, HQJ) +LCB = (THD, KTF) +DPL = (QGL, NRL) +SNG = (DQK, GNL) +HQR = (FSH, FJG) +GRF = (RQG, PVJ) +BBQ = (MHL, VKQ) +TMF = (LRD, DXH) +XTP = (HHK, SKZ) +DSB = (QBC, TRD) +QTG = (GFS, PLM) +PKH = (GFM, MXX) +BGD = (BCL, KNV) +LCC = (XJD, MTP) +DQN = (LQF, HMX) +RSJ = (XGP, NVH) +RXP = (PBB, NLF) +LXP = (NTF, HJC) +TGR = (NSL, SXK) +MKF = (MJQ, KXN) +BVC = (LJX, MLL) +BBA = (TVV, VLF) +PDN = (KGB, FGQ) +PLM = (FCF, DDF) +FHJ = (RLP, NHB) +VVT = (FGV, LDN) +STZ = (VRP, CBP) +FVK = (MHR, GMS) +QJX = (PXM, RGB) +GGS = (BGV, CBG) +XRQ = (CBP, VRP) +PSP = (FQF, HBL) +KMM = (RKS, RPB) +VMG = (NRL, QGL) +KXV = (NBM, NBM) +JLF = (MBM, FML) +RLN = (RSL, HVM) +TFF = (KXV, HBV) +DLK = (MCN, RJD) +BTF = (TVH, TDN) +MCR = (PPN, CKH) +TLD = (QSM, NQT) +QKX = (XSS, NDD) +VJC = (HTH, LXP) +XVV = (HMG, QSR) +DNB = (HFN, SPV) +JTQ = (NNJ, FCJ) +XLB = (KPM, SMH) +KSJ = (BGV, CBG) +VDS = (VGN, XXC) +CKH = (PSJ, KCF) +CFJ = (GCF, GCF) +QDF = (VRC, HTT) +VFC = (XJD, MTP) +MPF = (SMR, GVJ) +LRX = (NXS, BCB) +KBD = (MXX, GFM) +XMX = (NJX, GFC) +GHS = (FTG, XRG) +PMN = (QJB, HXJ) +AAA = (PBJ, RXK) +FXN = (VJR, VFM) +XKD = (CSF, FVL) +RQF = (LKM, VKC) +CTQ = (THQ, RBB) +RPJ = (DJK, FGN) +FML = (VFB, TLP) +TKG = (HJP, JSC) +JVQ = (XKD, HGV) +TFR = (QJX, CTB) +JRP = (SJH, BRX) +QGL = (SJR, HTD) +KDJ = (NQB, QLH) +SSD = (RQM, FCQ) +THQ = (VVL, QRN) +CBP = (KKH, XSQ) +LKM = (PFX, CHX) +VSA = (LQF, HMX) +XSQ = (LTT, FHJ) +FDR = (RQQ, XJF) +JQN = (PPN, CKH) +SRF = (KRM, JSB) +NLJ = (PTT, PTT) +PVJ = (DDP, TFL) +CFL = (QML, CTN) +FLM = (FMP, CRV) +DVS = (SSF, DCK) +DXH = (PND, XXP) +PLV = (RDF, NDJ) +NLF = (PQS, LQR) +NMN = (MPT, PLV) +PSN = (TGV, QCP) +RTL = (HGP, FVK) +SJP = (SDH, NBG) +LLG = (TFR, QTV) +DRT = (MFX, PKV) +BQN = (SDH, NBG) +RGB = (XMN, QXP) +NNJ = (BNP, QDF) +JQL = (TCX, TCX) +CRH = (MQF, CDQ) +RBR = (SNG, MVG) +HLP = (MVV, XFV) +MKZ = (HMX, LQF) +TTT = (DRR, TQS) +NHD = (RTC, MJS) +GFX = (DCT, QPJ) +JXD = (KNP, BPD) +XCM = (HJS, NPF) +QGQ = (GRF, JPH) +MKQ = (QLG, CSK) +VJQ = (TVD, MVF) +SBX = (KDR, LHN) +JPG = (BST, SPB) +QRN = (KPG, SLB) +MXX = (LLX, GGN) +QJH = (GVG, XML) +NMQ = (CLT, HXD) +MMM = (BJK, QTG) +PRK = (JTQ, HJJ) +RPB = (CVV, CRN) +LCJ = (QGB, KKM) +FGQ = (DQT, CBM) +SMJ = (GSD, TXM) +KPH = (JPG, XQQ) +BRB = (MQF, CDQ) +HNX = (LDT, JQG) +SXL = (MJS, RTC) +XNF = (NVN, FXN) +LBC = (MNM, VSQ) +BSN = (CFJ, HKJ) +FSN = (SHQ, CTP) +VKC = (CHX, PFX) +MJQ = (THR, FSN) +CGP = (TFJ, CMC) +NFQ = (JPG, XQQ) +NDS = (XPL, KNQ) +LBM = (DGT, HMT) +PXT = (GFH, VHH) +RBB = (QRN, VVL) +JPR = (QJH, HBF) +QSH = (BVC, RSG) +SPV = (NMQ, LMQ) +JSQ = (SXS, CPD) +XXP = (FHQ, BKL) +BQR = (FTG, XRG) +QMS = (KST, RLL) +VSQ = (SHG, GPV) +TGB = (HJS, NPF) +XHV = (NVH, XGP) +CMC = (XBL, TDM) +LQR = (CQF, HQR) +DLF = (BSJ, DGF) +DCC = (BKR, GLT) +VVB = (PGB, PDN) +TVB = (NNC, RXP) +GRT = (PSN, HNB) +VBC = (GJG, DSB) +CVZ = (MRM, SDK) +GQT = (PTL, QCT) +MVF = (VKL, XNJ) +RKS = (CVV, CRN) +MSC = (GVJ, SMR) +KCN = (FCB, RMP) +LFN = (TXR, QKJ) +MQF = (RSJ, XHV) +XRP = (QHX, FDX) +JDH = (SNG, MVG) diff --git a/day8/data/test_input_1 b/day8/data/test_input_1 new file mode 100644 index 0000000..9029a1b --- /dev/null +++ b/day8/data/test_input_1 @@ -0,0 +1,9 @@ +RL + +AAA = (BBB, CCC) +BBB = (DDD, EEE) +CCC = (ZZZ, GGG) +DDD = (DDD, DDD) +EEE = (EEE, EEE) +GGG = (GGG, GGG) +ZZZ = (ZZZ, ZZZ) diff --git a/day8/data/test_input_2 b/day8/data/test_input_2 new file mode 100644 index 0000000..7d1b58d --- /dev/null +++ b/day8/data/test_input_2 @@ -0,0 +1,5 @@ +LLR + +AAA = (BBB, BBB) +BBB = (AAA, ZZZ) +ZZZ = (ZZZ, ZZZ) diff --git a/day8/data/test_input_3 b/day8/data/test_input_3 new file mode 100644 index 0000000..5b3fa58 --- /dev/null +++ b/day8/data/test_input_3 @@ -0,0 +1,10 @@ +LR + +11A = (11B, XXX) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX) diff --git a/day8/run.py b/day8/run.py new file mode 100755 index 0000000..23c2b08 --- /dev/null +++ b/day8/run.py @@ -0,0 +1,100 @@ +#!/usr/bin/env pypy3.10 + +import sys +import argparse +import math +import itertools + + +def parse(filename: str): + nodes = {} + with open(filename) as stream: + route = stream.readline().strip() + junk = stream.readline().strip() + for line in stream.readlines(): + line = line.strip()\ + .replace(" = ", ",")\ + .replace("(", "")\ + .replace(")", "")\ + .replace(", ", ",") + key, left, right = line.split(",") + nodes[key] = (left, right) + return route, junk, nodes + + +def step(route, node): + direction = next(route) + return node[0] if direction == 'L' else node[1] + + +def part1(filename, debug=False) -> int: + route, junk, nodes = parse(filename) + + steps = 0 + route = itertools.cycle(route) + name = 'AAA' + while name != 'ZZZ': + steps += 1 + name = step(route, nodes[name]) + if debug: + print(f"{steps} {name}") + + return steps + + +class Path: + def __init__(self, route: str, nodes, start: str): + self.route = itertools.cycle(route) + self.nodes = nodes + self.name = start + + def step(self): + direction = next(self.route) + node = self.nodes[self.name] + self.name = node[0] if direction == 'L' else node[1] + + def is_end(self): + return self.name.endswith('Z') + + +def part2(filename, debug=False): + route, junk, nodes = parse(filename) + paths = [Path(route, nodes, key) \ + for key in nodes.keys() if key.endswith('A')] + loop = [0] * len(paths) + spans = [0] * len(paths) + steps = 0 + while True: + for ndx, path in enumerate(paths): + path.step() + if path.name.endswith('Z') and spans[ndx] == 0: + if loop[ndx]: + spans[ndx] = steps - loop[ndx] + else: + loop[ndx] = steps + if all(spans): + break + steps += 1 + if debug: + print(loop) + print(spans) + return math.lcm(*spans) + + +def main(args=None): + parser = argparse.ArgumentParser(description="advent of code 2023 day 6") + parser.add_argument('filename') + parser.add_argument('--part1', action='store_true') + parser.add_argument('--part2', action='store_true') + parser.add_argument('--debug', action='store_true') + options = parser.parse_args(args) + + if options.part1: + print(f"part 1: {part1(options.filename, debug=options.debug)}") + if options.part2: + print(f"part 2: {part2(options.filename, debug=options.debug)}") + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) -- 2.23.0