diff options
-rw-r--r-- | day8.in | 700 | ||||
-rw-r--r-- | day8.zig | 208 |
2 files changed, 908 insertions, 0 deletions
@@ -0,0 +1,700 @@ +LRLRRLRLRLLRRRLLLRLLRRLLRRRLRLRLRRRLRRLRLRRRLRRRLRRRLRRRLRRLRRRLRRRLRRLLLRLLRLRRRLRRRLRRLRLRLRLRRRLRRRLRRRLRRLRRLRRLLRRLRRRLLRRLRRRLRRRLRRRLRLRRLRLRRRLRRLLRLRLLRLRLRRRLRLRRLLRRRLRLRLRLRLRLRRLRLRRLLLLRRLRRLRRRLRRLRRLRRRLRRLRRRLLRLRRLLRLRRLRRLRRLLRRRLRLRLRRRLRRLRLLRLRRRR + +TNX = (BBN, MXH) +TCN = (VBD, LTV) +DXP = (GMJ, CMG) +RRM = (FHL, FHB) +DFG = (MVT, FTP) +GFJ = (TRG, LFT) +FKL = (SFR, NRR) +GMJ = (RRM, NRT) +FPM = (GTQ, NSH) +RKL = (DSC, VNR) +RXK = (RQR, TQX) +GGV = (DFG, TNJ) +KVR = (BBD, RHV) +RVJ = (MVJ, MNN) +XCM = (QMM, BTG) +PMS = (PRQ, BMN) +BHM = (QGQ, KNC) +FMC = (NTT, HDH) +BNX = (DSC, VNR) +QSJ = (XFR, JMV) +JMM = (CDT, SXX) +BNK = (MTL, RVF) +CBQ = (VPF, VQD) +KKK = (VKD, SJH) +FXH = (CMG, GMJ) +BSF = (GFQ, HSV) +XHN = (SNR, FPM) +BNG = (DMT, MPL) +JQT = (HXB, STK) +VGR = (CVT, RSF) +HMD = (RTN, MGT) +QBD = (FKD, PCL) +RXH = (SKN, DBR) +VDJ = (VLB, RCG) +DMF = (VNJ, DDM) +THR = (LVL, GGV) +QVH = (VQD, VPF) +XVX = (JGQ, VQG) +LCV = (RSJ, BHM) +GHN = (FTH, VXF) +QPF = (PKQ, HPQ) +DSS = (JHF, FDN) +VHJ = (TCN, TVC) +KVJ = (FGH, HCV) +VHN = (VQG, JGQ) +SMF = (NQC, JQK) +MVQ = (GLB, LGG) +JKX = (XNC, XNC) +LDH = (GLB, LGG) +SJH = (XHL, BKG) +HDM = (PSQ, LJS) +XKF = (BVP, VGJ) +PJD = (RVC, QDT) +TKM = (MLD, KTS) +KLM = (KTC, VJV) +BCT = (CJS, PSJ) +SJB = (XFB, MCX) +HPR = (DNM, JQJ) +RTN = (LVK, CFK) +GXD = (JPS, GFJ) +CVV = (MJR, VNS) +CLF = (DHK, TXC) +LFT = (FMQ, KPB) +RGJ = (FJR, GHZ) +MLF = (DPD, CKR) +DCS = (RNG, LNH) +LXR = (PFM, NLX) +BKJ = (SKM, SLQ) +SHL = (HDM, GNS) +STN = (SGX, LBD) +BQB = (GRR, FFB) +TPT = (BNP, JRK) +TKP = (GHN, CRT) +BHJ = (QJL, BDF) +JFC = (MKK, LCX) +LNQ = (KVP, TVT) +XKR = (LXM, BHJ) +MLX = (TDC, LCV) +MJX = (BNP, JRK) +RXX = (FMR, FMR) +MHG = (SMF, KVT) +CMJ = (XNV, CVV) +JKG = (FLM, QHQ) +SHT = (HXB, STK) +PDS = (QGG, NNZ) +NSH = (JBX, GLR) +BVP = (MKN, SKQ) +LKC = (QCR, CQJ) +AAA = (PFM, NLX) +RXR = (FMR, QNR) +VBH = (XGF, CMJ) +QNM = (GXD, PRT) +VGV = (QQR, SXP) +PRT = (GFJ, JPS) +VXF = (XBB, DVX) +BBD = (XRD, GQX) +BTG = (CSJ, DFN) +XSF = (CLF, GLV) +NXB = (TDC, LCV) +FBK = (BCT, BMM) +HXB = (TLV, DKM) +JKH = (DBT, GBX) +JDL = (HQT, HTH) +PFV = (BBN, MXH) +KNC = (NVM, GVM) +GPF = (QBD, HBN) +JLJ = (HPR, TKB) +LQN = (XJQ, JLJ) +FFN = (FMB, FHR) +SCP = (XRS, XVM) +MQL = (SMJ, SXF) +QGQ = (GVM, NVM) +KMF = (FQF, XVD) +QCR = (VGV, CDR) +LXM = (QJL, BDF) +TDV = (VHL, MML) +KTM = (NQL, TCT) +XKS = (JMJ, LFN) +JHJ = (FKG, LJM) +VHL = (LMB, PKR) +CDT = (QJJ, HFM) +TVC = (LTV, VBD) +XBP = (CFM, VDP) +LQJ = (XVM, XRS) +VDP = (HNL, GRT) +XHL = (HLR, PDR) +CQD = (VNJ, DDM) +NSG = (BMH, JKG) +SPZ = (DFV, QDG) +NCV = (FRM, CBF) +SVV = (LLD, JKH) +LFN = (MDS, PHG) +KPC = (NVV, MBF) +VDN = (QVP, HQD) +DSC = (PMK, TKG) +MML = (LMB, PKR) +FHS = (VBF, CXX) +DFT = (XKF, SLC) +VGG = (SSS, SBH) +LDS = (QSK, XKR) +NDB = (XRG, SHS) +GRR = (MBL, GVT) +QKL = (FXJ, TRC) +DJK = (LNF, XVF) +NKF = (KTS, MLD) +BPS = (STL, MMJ) +KXT = (BJD, CHD) +BCS = (DFC, XHN) +LSH = (LJT, QBL) +QMM = (DFN, CSJ) +MNH = (DHH, CTV) +RLG = (QFG, THR) +GNF = (FVB, FDQ) +KDX = (VHJ, MBB) +PBN = (XBP, QPT) +SFR = (DHC, GPF) +MQM = (CSK, LQN) +FJR = (KMT, PPM) +JPS = (TRG, LFT) +VLT = (MJF, XLB) +FKD = (NRN, NSL) +KNP = (MML, VHL) +GHZ = (PPM, KMT) +MBL = (PGG, QDJ) +FHR = (QSJ, DLH) +RVL = (BPD, PMS) +QVF = (CQC, RGJ) +VFH = (MCX, XFB) +SRS = (PKQ, HPQ) +HDH = (VLT, GCX) +HMV = (CQJ, QCR) +VTT = (QVH, CBQ) +PPM = (FBK, RMC) +RST = (MKS, KDJ) +FQF = (SFV, HTM) +CQJ = (CDR, VGV) +CBT = (JNV, GJN) +XNC = (VTT, TFL) +BMM = (PSJ, CJS) +FDR = (GNF, TJN) +HQD = (MFB, MVC) +DKK = (NDV, SVB) +VTK = (TPM, TPM) +NVV = (NFM, JKB) +HNL = (XRF, BGM) +KPB = (PRG, VQL) +MJN = (NQL, TCT) +FLM = (LKT, QKL) +QQJ = (MJN, KTM) +XNH = (QDT, RVC) +TQX = (CHN, BQB) +FMR = (LXR, LXR) +GHX = (QGG, QGG) +XFB = (FDT, JSX) +TCL = (LGH, RPL) +VTP = (HMD, PRP) +TLV = (QFK, NDH) +GSA = (QDG, DFV) +VKD = (XHL, BKG) +HTH = (CBT, GQF) +MVJ = (PJD, XNH) +KTS = (TKP, DKB) +HBD = (DSS, PPX) +BGM = (XSK, SPR) +LLD = (DBT, GBX) +CQX = (PCD, CSX) +KMP = (QPT, XBP) +HPQ = (MTN, HPV) +SQJ = (VTK, VTK) +PRK = (JXC, RBS) +VXX = (VHN, XVX) +XFJ = (KDX, DHD) +CRT = (VXF, FTH) +FVH = (TDV, KNP) +BMB = (QMM, BTG) +FMB = (DLH, QSJ) +BDF = (QPF, SRS) +QDT = (MXK, GJT) +NQL = (GSM, NLT) +JCB = (HSV, GFQ) +DQL = (QHD, JCS) +DHK = (SCP, LQJ) +MNN = (XNH, PJD) +DJP = (KKR, MQM) +CVT = (RLG, JQM) +MMB = (RXH, JTT) +BSX = (PBX, JPV) +MLD = (DKB, TKP) +GKR = (PBX, JPV) +NLX = (RKL, BNX) +CXD = (VGL, NDB) +NPL = (KDX, DHD) +KVP = (NHB, DQL) +QGT = (PMG, RLX) +SLQ = (DKK, RXG) +HVG = (CQC, CQC) +JJL = (DDK, DFT) +XSK = (GHT, CQX) +SPT = (LMF, XKQ) +HCV = (RVJ, SMT) +TKG = (VDR, KBD) +XKQ = (BKJ, GCR) +TVV = (KPJ, FPR) +KBD = (VDG, MNV) +MXT = (XVX, VHN) +LFC = (QDG, DFV) +HCM = (MCS, VTD) +RSJ = (QGQ, KNC) +PTR = (FFH, TCH) +RBS = (XSF, BFS) +VPF = (DJP, QQV) +GLV = (DHK, TXC) +MRD = (VGR, BPC) +VGJ = (SKQ, MKN) +QGA = (KMT, PPM) +HQT = (CBT, GQF) +BLC = (FKG, LJM) +RDP = (TDB, HLX) +BMQ = (JFD, JTR) +QGG = (RLL, VBV) +CMG = (RRM, NRT) +PCD = (CFJ, PLX) +JMV = (KPL, VDN) +VBV = (CKC, PDV) +KGC = (DLJ, JXV) +FMN = (JCB, BSF) +KKJ = (KPJ, FPR) +QQF = (LQH, CRN) +VPH = (MVQ, LDH) +JHF = (KLM, FLJ) +NBB = (CJK, KPC) +SKM = (DKK, RXG) +XGG = (KPC, CJK) +HBQ = (QGT, MBX) +QCM = (LGH, RPL) +CBF = (PFV, TNX) +HTQ = (KCN, TCX) +JBX = (SJB, VFH) +DDM = (XKS, QTC) +DLH = (XFR, JMV) +BNP = (PGV, FVH) +CHT = (VDJ, BND) +PHG = (JFC, PPN) +XSV = (SXX, CDT) +MVT = (LHV, VPH) +NFM = (SVV, NHM) +JRJ = (VGL, NDB) +NNZ = (VBV, RLL) +GNS = (PSQ, LJS) +PKQ = (HPV, MTN) +MPL = (TDL, KRP) +LHA = (DXP, FXH) +RLX = (MNH, KFM) +RTG = (LGS, VTP) +VRK = (JCQ, QNP) +MQN = (NRR, SFR) +MCX = (JSX, FDT) +FFB = (GVT, MBL) +NRN = (TPT, MJX) +JSQ = (VBN, JBQ) +KDB = (XGG, NBB) +MBX = (RLX, PMG) +KPL = (QVP, HQD) +SCK = (BFR, BMQ) +QVP = (MVC, MFB) +NGS = (KMJ, NMT) +HLR = (JCF, RDP) +TRC = (JKX, TQC) +SNR = (GTQ, NSH) +JPV = (HQM, SPV) +NHB = (QHD, JCS) +DDJ = (KVT, SMF) +CSX = (PLX, CFJ) +PJL = (JDL, CGK) +SPV = (PJL, QFV) +VNS = (PRK, GNN) +KKX = (FRR, MQL) +PBX = (HQM, SPV) +HVN = (FRR, MQL) +NGN = (GNS, HDM) +MTN = (RTG, FKM) +VDV = (GRB, FGV) +FTN = (QFB, PTR) +SMT = (MNN, MVJ) +VVB = (JBQ, VBN) +DNM = (KDB, BCX) +HVD = (TXX, RVB) +QQV = (MQM, KKR) +FLD = (JRJ, CXD) +TRG = (KPB, FMQ) +FDN = (FLJ, KLM) +VSC = (VTK, FPK) +KMH = (BBD, RHV) +HFM = (RKC, DLT) +VQQ = (PML, GXJ) +KTC = (TQN, FHS) +TMF = (VDV, CBB) +VNN = (CRN, LQH) +LVK = (BNG, MXG) +PLH = (TSF, PKS) +GBX = (LNQ, BGL) +PSJ = (PLH, SGS) +QJJ = (RKC, DLT) +VLH = (DMF, CQD) +VLB = (BTM, FLD) +CSK = (XJQ, JLJ) +FVB = (VXX, MXT) +RLL = (CKC, PDV) +GNN = (JXC, RBS) +MXH = (LQR, RXK) +LJS = (RVL, VLD) +BCX = (NBB, XGG) +CRR = (SGX, LBD) +LGG = (HKC, CGS) +RDR = (NTT, HDH) +KFM = (DHH, CTV) +GCR = (SKM, SLQ) +TQC = (XNC, NPZ) +CLH = (GHX, PDS) +BND = (VLB, RCG) +GHS = (RST, XNG) +SLC = (VGJ, BVP) +HGS = (XKR, QSK) +SHJ = (KJJ, TLD) +TXC = (SCP, LQJ) +SSS = (JMM, XSV) +JQK = (BNK, SGQ) +PMT = (KVJ, PQN) +SCH = (KVJ, PQN) +KMT = (FBK, RMC) +JXC = (BFS, XSF) +DFC = (SNR, FPM) +QFK = (KXT, GKD) +QQR = (HGT, FTN) +CKC = (RNF, TMF) +SFT = (BPC, VGR) +XTB = (VVB, JSQ) +RNF = (CBB, VDV) +MVC = (FQK, HVD) +FTH = (DVX, XBB) +VJV = (FHS, TQN) +XNG = (MKS, KDJ) +VNR = (PMK, TKG) +JFD = (VMJ, HBD) +FPR = (SCK, GNK) +CBB = (FGV, GRB) +JRK = (FVH, PGV) +XLB = (DJK, XFS) +TKB = (DNM, JQJ) +SVB = (FDR, CKF) +BJD = (HHH, HHH) +LJM = (TKM, NKF) +XVM = (QTF, FMN) +DVX = (XCM, BMB) +TXX = (VCB, GHS) +VTD = (CHT, RVT) +PKS = (QCM, TCL) +HXK = (SPT, BVQ) +GKD = (BJD, CHD) +RCN = (TCX, KCN) +NSL = (MJX, TPT) +MBF = (NFM, JKB) +GHR = (QGT, MBX) +JCQ = (CRR, STN) +QPT = (CFM, VDP) +JTT = (DBR, SKN) +CJS = (PLH, SGS) +PCL = (NRN, NSL) +BBN = (RXK, LQR) +LTV = (PBN, KMP) +PRQ = (RDL, RDL) +SXF = (RXX, RXR) +GJT = (VQQ, DVT) +RNG = (PGN, MTH) +QFV = (JDL, CGK) +JSX = (MHG, DDJ) +CXX = (JHJ, BLC) +FTP = (VPH, LHV) +VBD = (KMP, PBN) +RXG = (NDV, SVB) +PDV = (TMF, RNF) +NCC = (SSS, SBH) +KPJ = (GNK, SCK) +DPJ = (SMX, HCM) +PKR = (VGG, NCC) +XVD = (SFV, HTM) +SGS = (TSF, PKS) +DFV = (TLG, CGM) +MXG = (DMT, MPL) +RQR = (BQB, CHN) +JQR = (XGF, CMJ) +XDL = (CBF, FRM) +DMT = (TDL, KRP) +LCS = (RDR, FMC) +GVT = (PGG, QDJ) +CDR = (SXP, QQR) +CSJ = (VNQ, XTB) +NMT = (SQJ, VSC) +PVJ = (LJT, QBL) +XGF = (XNV, CVV) +FKM = (VTP, LGS) +CHD = (HHH, CLH) +SBH = (JMM, XSV) +QNR = (LXR, ZZZ) +PQN = (FGH, HCV) +TNJ = (FTP, MVT) +RDL = (LFC, LFC) +CHN = (GRR, FFB) +MCS = (CHT, RVT) +GXJ = (MQN, FKL) +TDC = (BHM, RSJ) +VLD = (BPD, PMS) +GLB = (CGS, HKC) +RVB = (GHS, VCB) +MKK = (VNN, QQF) +XNV = (MJR, VNS) +CGS = (PVJ, LSH) +VQD = (QQV, DJP) +DBT = (LNQ, BGL) +PMK = (KBD, VDR) +FPK = (TPM, QJN) +LMF = (BKJ, GCR) +BGL = (KVP, TVT) +HVZ = (FXH, DXP) +GVM = (SCH, PMT) +MMJ = (HTQ, RCN) +PRP = (RTN, MGT) +FHL = (GHR, HBQ) +NLT = (LDS, HGS) +HVJ = (MRD, SFT) +FGV = (MMB, HXD) +NHM = (LLD, JKH) +QHS = (DFC, XHN) +LHV = (LDH, MVQ) +LBA = (VTT, TFL) +PPX = (FDN, JHF) +VBF = (JHJ, BLC) +DHC = (QBD, HBN) +MJF = (DJK, XFS) +JGQ = (MLF, RTF) +CKF = (TJN, GNF) +RKC = (HMV, LKC) +TCT = (NLT, GSM) +HBN = (FKD, PCL) +VQG = (MLF, RTF) +FHB = (GHR, HBQ) +PGN = (VGK, QNM) +NDH = (KXT, GKD) +SKN = (MLX, NXB) +KCN = (SHT, JQT) +MKS = (BCS, QHS) +FDQ = (MXT, VXX) +FXJ = (JKX, JKX) +GLR = (VFH, SJB) +RTF = (CKR, DPD) +PFP = (BVQ, SPT) +SHS = (KMF, KKD) +HTM = (HVG, QVF) +FMQ = (PRG, VQL) +GRB = (MMB, HXD) +LKT = (FXJ, FXJ) +GJN = (MQB, HVJ) +NDV = (CKF, FDR) +JGC = (DLJ, JXV) +RVT = (BND, VDJ) +RPL = (VBH, JQR) +TCX = (JQT, SHT) +CQC = (FJR, FJR) +MXK = (VQQ, DVT) +DHD = (MBB, VHJ) +JQJ = (BCX, KDB) +FVK = (KMJ, NMT) +LJT = (MPB, VLH) +PMG = (KFM, MNH) +GSM = (LDS, HGS) +QTF = (JCB, BSF) +TSF = (TCL, QCM) +VQL = (SSN, VMK) +HHH = (GHX, GHX) +QDG = (CGM, TLG) +PFM = (RKL, BNX) +XFS = (LNF, XVF) +RMC = (BMM, BCT) +JCF = (TDB, HLX) +HXD = (JTT, RXH) +NVM = (PMT, SCH) +KKR = (CSK, LQN) +TQN = (CXX, VBF) +FQK = (TXX, RVB) +PLX = (NSG, BJP) +DFN = (VNQ, XTB) +QJL = (SRS, QPF) +MKN = (BNM, DPJ) +RVC = (MXK, GJT) +MPB = (DMF, CQD) +XRD = (BSX, GKR) +QSK = (LXM, BHJ) +QNP = (CRR, STN) +DKM = (NDH, QFK) +MBB = (TCN, TVC) +PHP = (MMJ, STL) +NQC = (SGQ, BNK) +NRR = (GPF, DHC) +LCX = (QQF, VNN) +PDR = (JCF, RDP) +HPV = (FKM, RTG) +BNM = (SMX, HCM) +VBN = (SHL, NGN) +NTQ = (NPL, XFJ) +DDK = (XKF, SLC) +RRR = (DFT, DDK) +DDH = (KJJ, TLD) +CTV = (SKT, QQJ) +QDH = (NPL, XFJ) +QJN = (PVT, HVZ) +JQM = (THR, QFG) +HSV = (JGC, KGC) +DLJ = (NLH, KKK) +JCS = (QDH, NTQ) +SXX = (HFM, QJJ) +JMJ = (MDS, PHG) +CFM = (GRT, HNL) +FRM = (PFV, TNX) +LVL = (TNJ, DFG) +SFV = (HVG, HVG) +CFK = (BNG, MXG) +SGX = (TVV, KKJ) +FGH = (RVJ, SMT) +CFJ = (NSG, BJP) +BFR = (JFD, JTR) +RSF = (JQM, RLG) +KJJ = (RRR, JJL) +FRR = (SMJ, SXF) +GFQ = (JGC, KGC) +MDS = (JFC, PPN) +LNF = (LXH, VRK) +NLH = (SJH, VKD) +XRG = (KKD, KMF) +BPD = (PRQ, PRQ) +KDJ = (QHS, BCS) +JTR = (VMJ, HBD) +TDB = (SHJ, DDH) +TLG = (LCS, KFF) +VNJ = (XKS, QTC) +CGK = (HQT, HTH) +TVT = (DQL, NHB) +GRT = (XRF, BGM) +SKQ = (DPJ, BNM) +QDJ = (PHP, BPS) +MGT = (CFK, LVK) +SXP = (HGT, FTN) +KMJ = (SQJ, VSC) +HKC = (PVJ, LSH) +GQX = (GKR, BSX) +BJP = (BMH, JKG) +KRP = (FFN, VKT) +BKG = (HLR, PDR) +FDT = (MHG, DDJ) +PPN = (MKK, LCX) +XVF = (LXH, VRK) +MFB = (HVD, FQK) +GCX = (MJF, XLB) +STK = (TLV, DKM) +QTC = (JMJ, LFN) +JNV = (HVJ, MQB) +XBB = (XCM, BMB) +PGG = (PHP, BPS) +LQH = (HXK, PFP) +VCB = (XNG, RST) +TJN = (FVB, FDQ) +TFL = (QVH, CBQ) +QFB = (FFH, TCH) +GTQ = (GLR, JBX) +DVT = (GXJ, PML) +BPC = (RSF, CVT) +CGM = (KFF, LCS) +VGL = (SHS, XRG) +QHQ = (LKT, QKL) +PGV = (KNP, TDV) +HGT = (QFB, PTR) +MTH = (QNM, VGK) +DKC = (LFC, SPZ) +RVF = (FVK, NGS) +TPM = (PVT, PVT) +DLT = (LKC, HMV) +TDL = (FFN, VKT) +QBL = (MPB, VLH) +CRN = (PFP, HXK) +XRS = (FMN, QTF) +VDR = (VDG, MNV) +BVQ = (LMF, XKQ) +LNH = (PGN, MTH) +QFG = (LVL, GGV) +LGS = (PRP, HMD) +LMB = (NCC, VGG) +DPD = (RCB, DCS) +MTL = (NGS, FVK) +ZZZ = (NLX, PFM) +BFS = (CLF, GLV) +HLX = (DDH, SHJ) +XCA = (RLL, VBV) +DKB = (GHN, CRT) +GQF = (JNV, GJN) +TCH = (XDL, NCV) +XRF = (SPR, XSK) +CJK = (NVV, MBF) +DHH = (SKT, QQJ) +GHT = (PCD, CSX) +JXV = (NLH, KKK) +RCB = (LNH, RNG) +VMJ = (DSS, PPX) +LBD = (TVV, KKJ) +VKT = (FMB, FHR) +VDG = (KVR, KMH) +HQM = (QFV, PJL) +NRT = (FHB, FHL) +CKR = (RCB, DCS) +LGH = (VBH, JQR) +RHV = (XRD, GQX) +FKG = (NKF, TKM) +NTT = (GCX, VLT) +FLJ = (KTC, VJV) +BMN = (RDL, DKC) +JKB = (NHM, SVV) +LQR = (RQR, TQX) +JBQ = (NGN, SHL) +NPZ = (TFL, VTT) +BMH = (FLM, QHQ) +SKT = (KTM, MJN) +XJQ = (TKB, HPR) +SMX = (VTD, MCS) +SPR = (GHT, CQX) +VNQ = (VVB, JSQ) +LXH = (JCQ, QNP) +BTM = (CXD, JRJ) +VGK = (PRT, GXD) +VMK = (KKX, HVN) +SMJ = (RXX, RXX) +MJR = (GNN, PRK) +PML = (FKL, MQN) +KKD = (FQF, XVD) +PVT = (DXP, FXH) +GNK = (BMQ, BFR) +TLD = (JJL, RRR) +MNV = (KVR, KMH) +SGQ = (RVF, MTL) +KFF = (FMC, RDR) +PSQ = (RVL, VLD) +RCG = (FLD, BTM) +KVT = (JQK, NQC) +MQB = (SFT, MRD) +PRG = (SSN, VMK) +QHD = (NTQ, QDH) +XFR = (VDN, KPL) +FFH = (NCV, XDL) +STL = (HTQ, RCN) +SSN = (KKX, HVN) +DBR = (NXB, MLX)
\ No newline at end of file diff --git a/day8.zig b/day8.zig new file mode 100644 index 0000000..831f751 --- /dev/null +++ b/day8.zig @@ -0,0 +1,208 @@ +const std = @import("std"); +pub const log_level: std.log.Level = .info; + +pub fn main() !void { + try std.fmt.format(std.io.getStdOut().writer(), "Day 8 pt1: {}\n", .{try solve_pt1(std.heap.page_allocator, puzzle_input)}); + try std.fmt.format(std.io.getStdOut().writer(), "Day 8 pt2: {}\n", .{try solve_pt2(std.heap.page_allocator, puzzle_input)}); +} +const NodeValue = struct { + left: []const u8, + right: []const u8, +}; + +fn solve_pt1(a: std.mem.Allocator, input: []const u8) !u64 { + var spl = std.mem.split(u8, input, "\n\n"); + const instructions = spl.first(); + const nodes_str = spl.next() orelse return error.NoNodes; + var spl2 = std.mem.split(u8, nodes_str, "\n"); + var nodes = std.StringHashMap(NodeValue).init(a); + defer nodes.deinit(); + while (spl2.next()) |node_line| { + var toks = std.mem.tokenize(u8, node_line, " (,)="); + const key = toks.next() orelse return error.NoKey; + const left = toks.next() orelse return error.NoLeft; + const right = toks.next() orelse return error.NoRight; + try nodes.putNoClobber(key, .{ + .left = left, + .right = right, + }); + } + + var steps: u64 = 0; + var pos: []const u8 = "AAA"; + while (!std.mem.eql(u8, pos, "ZZZ")) { + for (instructions) |inst| { + const node_value = nodes.get(pos).?; + pos = switch (inst) { + 'R' => node_value.right, + 'L' => node_value.left, + else => return error.InvalidDirection, + }; + steps += 1; + } + } + return steps; +} +test "pt1" { + try std.testing.expectEqual(@as(u64, 6), try solve_pt1(std.testing.allocator, test_input)); +} +const HistEntry = struct { + node: []const u8, + step: u64, +}; +const Path = struct { + // current position + pos: []const u8, + + // list of the _endpoints_ we have reached. + endpoints: std.ArrayList(HistEntry), + + // at n*cycle + offset this path is finished where n is integer > 0 + offset: ?u64 = null, + cycle: ?u64 = null, + + fn init(a: std.mem.Allocator, start: []const u8) !Path { + return .{ + .pos = start, + .endpoints = std.ArrayList(HistEntry).init(a), + }; + } + + fn visit(self: *Path, node: []const u8) void { + self.pos = node; + } + + fn check(self: *Path, step: u64) !void { + if (self.cycle != null) return; // we already found the cycle for this one + + if (self.pos[2] == 'Z') { // we hit an endpoint + for (self.endpoints.items) |hi| { // did we aleady hit this endpoint? + if (std.mem.eql(u8, hi.node, self.pos)) { + self.offset = hi.step; + self.cycle = step - hi.step; + return; + } + } + try self.endpoints.append(.{ .node = self.pos, .step = step }); + } + } +}; +fn solve_pt2(a: std.mem.Allocator, input: []const u8) !u64 { + var spl = std.mem.split(u8, input, "\n\n"); + const instructions = spl.first(); + const nodes_str = spl.next() orelse return error.NoNodes; + var spl2 = std.mem.split(u8, nodes_str, "\n"); + var nodes = std.StringHashMap(NodeValue).init(a); + defer nodes.deinit(); + while (spl2.next()) |node_line| { + var toks = std.mem.tokenize(u8, node_line, " (,)="); + const key = toks.next() orelse return error.NoKey; + const left = toks.next() orelse return error.NoLeft; + const right = toks.next() orelse return error.NoRight; + try nodes.putNoClobber(key, .{ + .left = left, + .right = right, + }); + } + + var pos: []Path = blk: { + var pl = std.ArrayList(Path).init(a); + defer pl.deinit(); + var ki = nodes.keyIterator(); + while (ki.next()) |k| { + if (k.*[2] == 'A') { // ends with an A + std.log.info("start pos {s}", .{k.*}); + try pl.append(try Path.init(a, k.*)); + } + } + break :blk try pl.toOwnedSlice(); + }; + defer a.free(pos); + + var log = std.time.timestamp() + 10; + + var steps: u64 = 0; + while (!ends(pos)) { + // > repeat the whole sequence of instructions as necessary + // always repeat the whole set + for (instructions) |inst| { + for (pos) |*p| { + const node_value = nodes.get(p.pos).?; + p.visit(switch (inst) { + 'R' => node_value.right, + 'L' => node_value.left, + else => return error.InvalidDirection, + }); + } + } + steps += instructions.len; + + // logging... + const now = std.time.timestamp(); + if (now > log) { + for (pos) |p| { + std.log.info("pos {s}", .{p.pos}); + } + log = now + 10; + } + + // now check for cycles + for (pos) |*p| { + try p.check(steps); + } + // now... check if we have detected a cycle on _all_ tracks + for (pos) |p| { + if (p.cycle == null) break; + } else { + std.log.info("all routes have cycled, using LCM", .{}); + // great, so we haven't reached the end but we can probably calculate it. + var l = lcm(pos[0].cycle.?, pos[1].cycle.?); + for (pos[2..]) |p| { + l = lcm(l, p.cycle.?); + } + // so, this is our answer? + return l; + } + } + return steps; +} + +fn ends(pos: []Path) bool { + for (pos) |p| { + if (p.pos[2] != 'Z') { + return false; + } + } else { + std.log.err("ends true", .{}); + for (pos) |p| { + std.log.err("{s}", .{p.pos}); + } + return true; + } +} +fn lcm(a: u64, b: u64) u64 { + return (a * b) / std.math.gcd(a, b); +} +test "pt2" { + try std.testing.expectEqual(@as(u64, 6), try solve_pt2(std.testing.allocator, test_input2)); +} +const test_input = + \\LLR + \\ + \\AAA = (BBB, BBB) + \\BBB = (AAA, ZZZ) + \\ZZZ = (ZZZ, ZZZ) +; +const test_input2 = + \\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) +; +const puzzle_input = @embedFile("day8.in"); |