diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e57a2a..0dcbac5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,3 +14,4 @@ add_subdirectory(day04) add_subdirectory(day05) add_subdirectory(day06) add_subdirectory(day07) +add_subdirectory(day08) diff --git a/day08/CMakeLists.txt b/day08/CMakeLists.txt new file mode 100644 index 0000000..8669842 --- /dev/null +++ b/day08/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(day08 main.cpp) diff --git a/day08/input.txt b/day08/input.txt new file mode 100644 index 0000000..82e7dcb --- /dev/null +++ b/day08/input.txt @@ -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) \ No newline at end of file diff --git a/day08/main.cpp b/day08/main.cpp new file mode 100644 index 0000000..694b1ff --- /dev/null +++ b/day08/main.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +long calculateCyclusLength(const unordered_map> &nodes, const string &startNode, const string &instructions, + const regex &endRegex) { + string currentNode = startNode; + long steps = 0; + auto it = instructions.begin(); + + while (true) { + auto [left, right] = nodes.at(currentNode); + if (*it == 'L') + currentNode = left; + else + currentNode = right; + steps++; + it++; + if (it == instructions.end()) + it = instructions.begin(); + if (regex_match(currentNode, endRegex)) + break; + } + return steps; +} + +int main(int argc, char **argv) { + if (argc != 2) { + cout << "Usage: " << argv[0] << " inputfile" << endl; + return (EXIT_FAILURE); + } + + ifstream inputFile(argv[1]); + + if (!inputFile) { + cout << "Cannot open inputfile" << endl; + return (EXIT_FAILURE); + } + + string instructions; + getline(inputFile, instructions); + + string line; + unordered_map> nodes; + while (getline(inputFile, line)) { + if (line.empty()) + continue; + nodes[line.substr(0, 3)] = make_pair(line.substr(7, 3), line.substr(12, 3)); + } + + cout << "Part1: " << calculateCyclusLength(nodes, "AAA", instructions, regex("ZZZ")) << endl; + + vector startNodes; + for_each(nodes.begin(), nodes.end(), [&startNodes](auto &node) { + if (node.first.ends_with("A")) + startNodes.push_back(node.first); + }); + + vector cyclusLengths; + transform(startNodes.begin(), startNodes.end(), back_inserter(cyclusLengths), + [&nodes, &instructions](auto &startNode) { return calculateCyclusLength(nodes, startNode, instructions, regex("..Z")); }); + + long lcmResult = cyclusLengths.front(); + for_each(cyclusLengths.begin() + 1, cyclusLengths.end(), [&lcmResult](auto &cyclusLength) { lcmResult = lcm(lcmResult, cyclusLength); }); + cout << "Part2: " << lcmResult << endl; +}