Compare commits

...

2 commits

Author SHA1 Message Date
c6cb18da49 2023 day8/rust: add solution 2023-12-09 11:26:25 +00:00
bbddca6178 2023 day8: add data 2023-12-09 11:24:31 +00:00
6 changed files with 985 additions and 0 deletions

756
2023/data/day8.input Normal file
View file

@ -0,0 +1,756 @@
LLRRRLRLLRLRRLRLRLRRRLLRRLRRRLRRRLRRRLRRRLRRRLRRLRLLRRRLRRLLRLRLLLRRLRRLRLRLRLRRRLRLRRRLRRLLLRRRLLRRLLRRLLRRRLLLLRLRLRRRLRLRRRLRLLLRLRRLRRRLRRRLRRRLRRRLLRRLLLLRRLLRRLLRRLRLRRRLRRRLRRRLRRLRRRLRRLRRLRRLRLRRRLRRLRRRLRRRLRRLRLRRRLRRLLRLRRLRRRLRLRRLRRRLRRLRRLRRRLLRRRR
GXF = (XQB, GFH)
QQC = (HQF, BNK)
TPP = (XNG, FDD)
LQD = (MGR, GJN)
XNG = (RCM, BJG)
NQC = (KNT, DQF)
DGJ = (PGM, LSB)
RBF = (RCH, RCH)
DNH = (RTL, MLF)
VKF = (SRV, TQR)
MPT = (FVV, TVP)
TKX = (VRN, KNV)
XLQ = (MCF, MCF)
MNJ = (FRT, QGV)
STF = (LFQ, QDS)
FFH = (JVM, TCJ)
KRT = (GFC, HRX)
FVG = (QFS, RSJ)
DBH = (GXF, DJL)
RKP = (VNL, MSC)
VQX = (GGG, RPB)
FCM = (VMC, MGV)
SRL = (LVV, JQN)
HHM = (BDM, FRV)
GMN = (LPK, FHT)
QCF = (RCH, NJM)
PCB = (MDJ, KDM)
VMR = (THX, HHB)
XQK = (BJQ, LST)
FCS = (KPT, RSC)
XTG = (XTL, SVX)
FVF = (KXB, VVV)
NNR = (SBM, TPP)
NPH = (RHN, FRR)
GJF = (FXG, MLP)
TRR = (LVC, RMR)
NBS = (SFH, JGT)
SSH = (KTK, DDM)
CJH = (QJK, XHB)
DQF = (NSR, MJB)
FHT = (PFK, GPS)
GTJ = (QXC, XBR)
KQB = (JXT, KGR)
JLL = (GTJ, CBN)
QPH = (LTX, BDJ)
BSP = (MRH, BXJ)
QBX = (GPR, SHJ)
SPJ = (SLD, XQK)
PML = (TTV, BHX)
FQN = (TPJ, BTV)
GTK = (NBS, VNP)
DSQ = (RFN, QGB)
KTK = (JHR, FCM)
FXV = (BBN, VPK)
LJC = (VKH, PPQ)
NBA = (JBL, LSR)
RKK = (VTL, SNM)
FVV = (DQS, CSM)
MGJ = (QHP, DPL)
RND = (JRQ, XGJ)
DVP = (RBF, RBF)
JXR = (TJN, CVC)
FMV = (CVJ, BVZ)
XBL = (KFC, HHT)
GDR = (KCV, KCV)
NGN = (VKH, PPQ)
NJB = (VTH, FSQ)
MBD = (JKS, SFQ)
TGC = (PXP, TTF)
VMT = (XJN, CCH)
LBF = (QRB, SKN)
DGH = (CSD, RND)
SFH = (XHH, GSC)
QQD = (VTT, NLX)
BLB = (GHJ, KQD)
LFG = (TLH, XJT)
CQS = (FRR, RHN)
XRS = (QLF, KLC)
DJL = (GFH, XQB)
LJM = (RPM, HPF)
HHT = (LBF, VCS)
GFL = (LFG, MGQ)
TNX = (TSJ, HCK)
HPR = (MTG, TJX)
LKP = (BXL, BHG)
KRC = (DCT, CTS)
PSJ = (QPF, MQT)
CXG = (NPG, JQP)
QTK = (XBL, DSM)
SVP = (MLF, RTL)
NDT = (NLC, MLK)
TDR = (DJR, CJQ)
RHS = (HXN, PSZ)
PSZ = (VNG, NNK)
KKL = (GLH, SPJ)
RSB = (SFQ, JKS)
PQS = (XVK, LMV)
TTV = (MLG, FRH)
CJQ = (CTM, KCC)
VTT = (QSQ, TVV)
TCJ = (MTD, KKX)
CNM = (SXQ, RGK)
XCC = (DNP, FQN)
CXD = (TJX, MTG)
VTL = (JFV, DHN)
BJG = (FHB, QVJ)
MJR = (HDL, LSF)
CSV = (CTS, DCT)
LFQ = (LNX, RHQ)
MNL = (XBL, DSM)
NDR = (PGT, TPC)
CKS = (CDQ, GLT)
VVV = (BVL, QQC)
GGG = (JGS, VRC)
QRT = (SQJ, VSJ)
HQF = (NJK, NJK)
JGK = (FJK, PXJ)
RXG = (CLT, GTK)
TNH = (SJM, QNX)
HLX = (QJX, PGN)
FRR = (CKP, NHC)
QMK = (QVH, QLH)
FRT = (TMB, VRX)
KJD = (GBS, QMT)
RCH = (TGC, TGC)
JGF = (DKD, CHG)
TSM = (TDR, XHJ)
MTG = (DRP, KRR)
DCF = (NQC, KNM)
VPQ = (HRB, MGG)
XVK = (MPC, XMX)
NNK = (FKT, CMD)
TBF = (JDV, LQD)
TTH = (SJM, QNX)
NLX = (TVV, QSQ)
HGT = (LSF, HDL)
FCB = (KLC, QLF)
GBH = (HTJ, LXL)
BJQ = (XDH, RGV)
FLH = (FXV, SMJ)
XGN = (CHN, BLJ)
RGV = (QCB, TCC)
BCV = (NHF, NDH)
GQD = (LDC, TVB)
BCT = (KGS, QCH)
NGC = (MGJ, RPT)
LSL = (QVH, QLH)
SQJ = (TTH, TNH)
VNL = (RLV, CRK)
XCQ = (KQB, BLP)
CDL = (DJL, GXF)
MJB = (CRR, HHM)
GSP = (DQJ, FLV)
NCM = (SQN, VPJ)
JRQ = (RJM, CXG)
SXA = (QPH, CFB)
LBT = (GPL, NDJ)
QNX = (PJT, PQC)
PBV = (RRP, TSM)
CSD = (XGJ, JRQ)
MLK = (GLG, SKB)
CFB = (LTX, BDJ)
BCH = (HPQ, JBR)
BBN = (RHR, VMT)
KCV = (RHL, RHL)
SGG = (SMP, QSP)
GFB = (KCF, KJR)
TSD = (NSD, NDL)
CXL = (FVG, JCJ)
FSQ = (FQG, GXQ)
BQF = (HRB, MGG)
LRK = (JPG, BHR)
LBB = (BHX, TTV)
CXR = (BXX, STP)
MGV = (RLK, FDX)
FHB = (LCN, KSX)
JDQ = (GFK, BHD)
FJL = (GDR, GDR)
TSN = (RKJ, GLN)
VPK = (RHR, VMT)
VCS = (SKN, QRB)
BKG = (RSC, KPT)
LQB = (MMQ, BCT)
KJK = (SMF, VPM)
XMV = (PQS, RCX)
TCC = (GPP, KRT)
BFS = (DDP, VJJ)
FDD = (RCM, BJG)
BHG = (MKG, BSM)
GQP = (PRR, FFH)
GXQ = (BLH, FMB)
XBV = (NSH, GCB)
MCF = (QPH, CFB)
BTD = (BCH, GFM)
JQD = (VPQ, BQF)
JGT = (XHH, GSC)
KGS = (MGB, QQS)
JMF = (PSK, GDD)
VTZ = (NNR, NVQ)
JGS = (KHM, DTS)
CBF = (NDJ, GPL)
XPM = (MCF, VGZ)
RSJ = (VCC, MGS)
BLQ = (HJP, MPP)
HHB = (NKX, PXK)
JKS = (DKV, GMN)
GFH = (RXG, VGP)
MSC = (RLV, CRK)
KJR = (SLQ, FLH)
KFC = (VCS, LBF)
GGM = (KJK, QJF)
QDS = (RHQ, LNX)
TPC = (PFD, DJN)
DSM = (HHT, KFC)
BPJ = (RKK, GGV)
MLG = (PDG, SGF)
HTJ = (RBJ, PKL)
HJR = (MRH, BXJ)
JVA = (NVQ, NNR)
PXK = (CRV, RHB)
NJK = (CVJ, CVJ)
XPR = (PGT, TPC)
DTS = (FCS, BKG)
XJN = (TFT, LKP)
SNV = (DDT, LBL)
BXX = (KKQ, GBH)
PQM = (MXJ, FTT)
NSX = (HLX, GVH)
CVJ = (JBL, LSR)
HKQ = (VMR, DSR)
RQJ = (QFV, XMV)
CMQ = (KKL, QDL)
PGM = (VBL, KFF)
LST = (RGV, XDH)
CMD = (HKQ, SPB)
XSV = (LBB, PML)
JHB = (SSB, CXR)
LVC = (JHB, TVH)
QNT = (RBB, NDT)
QPF = (FJG, TKX)
NDH = (RRT, PQM)
TSJ = (LGH, FBN)
KDM = (GJJ, NVX)
HMJ = (HPF, RPM)
STP = (GBH, KKQ)
LDC = (LBT, CBF)
RCB = (BPN, JXR)
MSN = (PDF, JHF)
KKX = (HVX, BKX)
GLT = (VHR, GGM)
MRH = (LCD, CKD)
VGP = (CLT, GTK)
LLV = (MRN, PBV)
PDL = (DGH, LNK)
PFD = (RCB, VRH)
CRK = (NGC, KQR)
TVP = (CSM, DQS)
VTH = (GXQ, FQG)
RHJ = (SHN, PNR)
MMQ = (QCH, KGS)
GFK = (VDV, XCC)
PQC = (SRF, KML)
SHJ = (CHD, DCB)
QJF = (SMF, VPM)
QLF = (NGX, RKP)
LTX = (RNS, VHH)
RQB = (MGQ, LFG)
BHD = (XCC, VDV)
FQG = (BLH, FMB)
SNM = (JFV, DHN)
LRQ = (JDL, QBX)
SHP = (FRT, QGV)
DDP = (CRJ, SXV)
LMV = (XMX, MPC)
KMP = (HQB, SSK)
GXM = (SRV, TQR)
SMP = (JGK, GST)
KRH = (PBV, MRN)
RDM = (FKN, MSN)
FNF = (VJJ, DDP)
VKH = (CJX, PDB)
NHF = (PQM, RRT)
PBJ = (RMR, LVC)
FRG = (QJC, BPL)
RHG = (BGQ, XCQ)
RPB = (VRC, JGS)
KQD = (VBS, MBN)
LSR = (SRH, CSS)
KFF = (MFT, NSX)
TJX = (KRR, DRP)
GPL = (FPQ, SSH)
XNM = (BCH, GFM)
MPP = (RLX, FVF)
HQB = (DJJ, SPV)
SSK = (SPV, DJJ)
XVA = (SHP, MNJ)
TMT = (VRS, JHH)
NGX = (MSC, VNL)
SMF = (HFP, JMF)
SFQ = (DKV, GMN)
GBM = (NDH, NHF)
DKV = (FHT, LPK)
PTN = (FCD, SRL)
GPB = (CVS, GFD)
QFR = (BLQ, LCT)
TLH = (KMP, LFS)
TVG = (BHD, GFK)
RRT = (MXJ, FTT)
DCB = (BPC, GJF)
VRN = (CVH, PLG)
MGG = (RGR, DDB)
XND = (LGX, FCN)
HDC = (DJP, BPJ)
TCV = (NNV, MDV)
JQP = (LSL, QMK)
KLC = (NGX, RKP)
DPL = (VSL, GQP)
BHX = (MLG, FRH)
HNK = (LFQ, QDS)
RHR = (CCH, XJN)
RCM = (FHB, QVJ)
JVN = (RHL, VTZ)
HSS = (LXF, LXF)
XQB = (RXG, VGP)
XJQ = (NLN, XLD)
HFP = (PSK, GDD)
HCK = (FBN, LGH)
VHR = (KJK, QJF)
MLF = (MPT, SGJ)
TPS = (PGM, LSB)
HJJ = (CQS, NPH)
LMQ = (JQD, VPR)
GPR = (CHD, DCB)
QFS = (MGS, VCC)
SKB = (SMG, STS)
CKT = (CCJ, RJH)
SDV = (NGN, LJC)
DJB = (DVP, SHV)
CDR = (RQJ, BPH)
QHP = (VSL, GQP)
PFK = (HQJ, XSV)
PNM = (NRQ, JGF)
SQN = (LJM, HMJ)
KXB = (BVL, QQC)
NHX = (XDQ, PTN)
TFT = (BHG, BXL)
XDH = (TCC, QCB)
XFN = (QGB, RFN)
BLJ = (QRV, GGH)
QLH = (SGG, QHQ)
KPT = (LQB, TNG)
VBS = (PDL, PJH)
RFN = (GFL, RQB)
JDL = (GPR, SHJ)
NNV = (VSN, BRN)
JNV = (KDM, MDJ)
SLK = (FLV, DQJ)
JPG = (XRS, FCB)
DQJ = (NGR, XKM)
LMT = (GJC, BKT)
GFD = (DMP, XND)
RJM = (NPG, JQP)
GLH = (XQK, SLD)
SPB = (DSR, VMR)
MGQ = (TLH, XJT)
SNL = (MLR, VTM)
KNT = (MJB, NSR)
DDM = (FCM, JHR)
TDD = (GLN, RKJ)
RRX = (XLQ, XPM)
SGF = (SNL, FJF)
BTV = (GFB, SMX)
BPH = (XMV, QFV)
VSJ = (TNH, TTH)
DSD = (DVP, SHV)
JXT = (DGJ, TPS)
DDV = (NNV, MDV)
DRP = (KDS, TNJ)
MTD = (HVX, BKX)
CVH = (FFD, RDM)
LCD = (CMJ, CMJ)
NLC = (SKB, GLG)
XJT = (LFS, KMP)
CHG = (DHF, FVX)
MFT = (HLX, GVH)
HRX = (HPM, XGN)
KGR = (TPS, DGJ)
GLJ = (NSH, GCB)
GPP = (GFC, HRX)
TVV = (NFR, QNT)
QJK = (QKQ, KDV)
XHH = (NJB, PVR)
BHR = (FCB, XRS)
CKD = (CMJ, RRX)
XKM = (VQX, RDL)
PXJ = (GBM, BCV)
DCT = (HDC, BFG)
HXN = (NNK, VNG)
QGG = (BPH, RQJ)
DQS = (FKL, NCM)
STL = (DDT, LBL)
PDB = (FNF, BFS)
ZZZ = (TTF, PXP)
SHV = (RBF, QCF)
NGL = (GDR, XRQ)
QVH = (QHQ, SGG)
CBN = (XBR, QXC)
RNT = (KRC, CSV)
GCB = (DDF, LMQ)
NDL = (DDV, TCV)
SRV = (CDR, QGG)
DMP = (LGX, LGX)
RKJ = (KFG, FRG)
SKG = (KBH, LRQ)
QGB = (RQB, GFL)
XBR = (GQD, QJV)
DHN = (LMT, NBB)
LPK = (PFK, GPS)
QVS = (HJJ, TQJ)
MSV = (RJH, CCJ)
CCK = (SQJ, VSJ)
QHQ = (SMP, QSP)
PKL = (RVD, BDX)
JDV = (MGR, GJN)
FDX = (JFT, TNX)
DJN = (RCB, VRH)
XGJ = (CXG, RJM)
DJJ = (VKF, GXM)
VPR = (VPQ, BQF)
PGT = (PFD, DJN)
RGR = (RPS, NBT)
BRK = (BSP, HJR)
KKQ = (LXL, HTJ)
VRC = (DTS, KHM)
GST = (FJK, PXJ)
SLD = (BJQ, LST)
GHL = (NRQ, JGF)
HQJ = (PML, LBB)
BLH = (RNT, JFC)
SPV = (GXM, VKF)
VPM = (JMF, HFP)
RBB = (MLK, NLC)
FTT = (PVF, DVS)
XRQ = (KCV, JVN)
LSB = (VBL, KFF)
QMT = (CCK, QRT)
FBN = (XNM, BTD)
JFT = (TSJ, HCK)
HDL = (QHL, XNP)
BPC = (FXG, MLP)
TVB = (LBT, CBF)
KNM = (KNT, DQF)
CHN = (QRV, GGH)
SRH = (XQN, NNC)
LXF = (HXN, HXN)
VCC = (SKG, QQR)
VMM = (RGK, SXQ)
FCD = (LVV, JQN)
FMB = (RNT, JFC)
CNC = (PTN, XDQ)
KCC = (JLL, VFC)
CDQ = (VHR, GGM)
QFV = (RCX, PQS)
XQN = (RHG, TKF)
SMJ = (VPK, BBN)
SRF = (JDQ, TVG)
SKN = (RLS, RHJ)
KXX = (KHL, LFJ)
GJN = (BRK, FPX)
QGV = (VRX, TMB)
SXV = (GQM, KJD)
VGZ = (CFB, QPH)
JQN = (XFN, DSQ)
BKT = (CBT, PVD)
QJC = (PBJ, TRR)
BLP = (JXT, KGR)
TTF = (MMV, MFK)
PXP = (MMV, MFK)
PSK = (KMJ, QQD)
VPJ = (HMJ, LJM)
RPQ = (CDL, DBH)
RPS = (NDR, XPR)
QQS = (VDG, XJP)
GGH = (PCB, JNV)
KHL = (MLT, PSJ)
NPG = (QMK, LSL)
XDQ = (SRL, FCD)
MXJ = (PVF, DVS)
VGG = (XLD, NLN)
DNP = (TPJ, BTV)
XRN = (LRK, QXS)
XTS = (NQC, KNM)
FJF = (MLR, VTM)
MVL = (THG, GPB)
TPJ = (GFB, SMX)
FJG = (VRN, KNV)
NDX = (JDV, LQD)
JHR = (MGV, VMC)
KNV = (CVH, PLG)
NSH = (LMQ, DDF)
THG = (CVS, GFD)
RDL = (RPB, GGG)
BNK = (NJK, FMV)
FHG = (THG, GPB)
NKX = (RHB, CRV)
MMV = (CKS, FRS)
RHB = (GSP, SLK)
GVH = (QJX, PGN)
LFS = (HQB, SSK)
SJM = (PQC, PJT)
TVH = (CXR, SSB)
FKN = (JHF, PDF)
KRR = (TNJ, KDS)
HPQ = (FJL, NGL)
PDG = (FJF, SNL)
RRP = (TDR, XHJ)
LGX = (XVV, XVV)
QKQ = (TDD, TSN)
GQM = (GBS, QMT)
MQT = (FJG, TKX)
HRB = (RGR, DDB)
HQS = (DJB, DSD)
XMX = (MNL, QTK)
LGH = (XNM, BTD)
QJX = (PPC, KXX)
JBR = (FJL, NGL)
FRV = (HGT, MJR)
BXN = (QXS, LRK)
GFM = (HPQ, JBR)
MDV = (VSN, BRN)
PPQ = (PDB, CJX)
FRH = (PDG, SGF)
KBH = (QBX, JDL)
LNX = (XTG, MJV)
PHD = (XJQ, VGG)
DJR = (KCC, CTM)
LNK = (RND, CSD)
SVX = (HRJ, RPQ)
BVZ = (LSR, JBL)
STS = (CMQ, MGX)
DDF = (VPR, JQD)
GHJ = (MBN, VBS)
HVX = (CXD, HPR)
JBL = (CSS, SRH)
HPF = (BNS, QFR)
DSR = (THX, HHB)
KMJ = (VTT, NLX)
GFC = (XGN, HPM)
CJX = (FNF, BFS)
FKT = (SPB, HKQ)
MBN = (PDL, PJH)
NLN = (CXL, KNR)
GSC = (PVR, NJB)
LFJ = (MLT, PSJ)
NBT = (NDR, XPR)
RLK = (TNX, JFT)
SSB = (BXX, STP)
FJK = (GBM, BCV)
VRX = (CJH, KXH)
DJP = (RKK, GGV)
HRJ = (CDL, DBH)
XHB = (QKQ, KDV)
BVL = (HQF, HQF)
PVF = (VMM, CNM)
GLN = (KFG, FRG)
KHM = (BKG, FCS)
VHH = (MBJ, PHD)
XPV = (DJB, DSD)
MJV = (XTL, SVX)
BDJ = (VHH, RNS)
RLS = (SHN, PNR)
CBT = (RQM, JJX)
PRR = (JVM, TCJ)
DVS = (VMM, CNM)
KXH = (QJK, XHB)
SHD = (LXF, RHS)
GPS = (XSV, HQJ)
MGR = (BRK, FPX)
BXJ = (LCD, CKD)
RBJ = (RVD, BDX)
JFC = (KRC, CSV)
GDD = (QQD, KMJ)
KDS = (TBF, NDX)
BRN = (HSS, SHD)
QXC = (QJV, GQD)
GLG = (STS, SMG)
MGX = (QDL, KKL)
MLT = (MQT, QPF)
HPM = (BLJ, CHN)
CKP = (CNC, NHX)
KML = (TVG, JDQ)
AAA = (PXP, TTF)
BPZ = (MNJ, SHP)
FPQ = (DDM, KTK)
NSR = (CRR, HHM)
XLD = (CXL, KNR)
PLG = (FFD, RDM)
RPM = (BNS, QFR)
SGJ = (FVV, TVP)
BPL = (PBJ, TRR)
RHN = (NHC, CKP)
MGB = (XJP, VDG)
RJH = (BTK, FBK)
VNP = (JGT, SFH)
BDX = (SNV, STL)
VSN = (HSS, HSS)
LCT = (MPP, HJP)
NBB = (GJC, BKT)
VRS = (GHL, PNM)
JJX = (BLB, FBQ)
TMB = (KXH, CJH)
RLX = (KXB, VVV)
NJM = (TGC, ZZZ)
VNG = (CMD, FKT)
GJJ = (MSV, CKT)
CVC = (SNH, TMT)
CVS = (DMP, DMP)
MFK = (CKS, FRS)
XHJ = (DJR, CJQ)
FCN = (XVV, BPZ)
JVM = (KKX, MTD)
RQM = (FBQ, BLB)
SLQ = (FXV, SMJ)
BNS = (LCT, BLQ)
DKD = (FVX, DHF)
JHF = (MBD, RSB)
FBQ = (GHJ, KQD)
KDV = (TSN, TDD)
FVL = (HJJ, TQJ)
LXL = (PKL, RBJ)
VDV = (FQN, DNP)
BDM = (HGT, MJR)
VDG = (KHJ, SDV)
BFG = (DJP, BPJ)
PNR = (XPV, HQS)
XTL = (RPQ, HRJ)
PGN = (PPC, KXX)
XNP = (LLV, KRH)
VTM = (DNH, SVP)
VJJ = (CRJ, SXV)
NVQ = (SBM, TPP)
RLV = (NGC, KQR)
THX = (NKX, PXK)
MLP = (GLJ, XBV)
MPC = (MNL, QTK)
FPX = (BSP, HJR)
NHC = (NHX, CNC)
CRV = (SLK, GSP)
NNC = (RHG, TKF)
SNH = (JHH, VRS)
KNR = (FVG, JCJ)
CRJ = (GQM, KJD)
PJT = (SRF, KML)
XJP = (KHJ, SDV)
BXL = (BSM, MKG)
QRB = (RHJ, RLS)
SMX = (KCF, KJR)
CSM = (FKL, NCM)
MGS = (QQR, SKG)
RTL = (SGJ, MPT)
CND = (NDL, NSD)
BTK = (QVS, FVL)
TNJ = (TBF, NDX)
JFV = (LMT, NBB)
CMJ = (XLQ, XLQ)
CCJ = (BTK, FBK)
SXQ = (FHG, MVL)
MLR = (DNH, SVP)
PJH = (LNK, DGH)
KFG = (QJC, BPL)
MRN = (RRP, TSM)
LBL = (HNK, STF)
NFR = (RBB, NDT)
NGR = (RDL, VQX)
PVR = (VTH, FSQ)
LVV = (XFN, DSQ)
RCX = (XVK, LMV)
FLV = (NGR, XKM)
CRR = (FRV, BDM)
BSM = (CND, TSD)
FVX = (XRN, BXN)
TKF = (XCQ, BGQ)
QSQ = (NFR, QNT)
XVV = (SHP, MNJ)
RVD = (SNV, STL)
MKG = (TSD, CND)
QCB = (GPP, KRT)
NVX = (MSV, CKT)
GGV = (VTL, SNM)
GJC = (PVD, CBT)
QSP = (JGK, GST)
VBL = (MFT, NSX)
DDB = (RPS, NBT)
BKX = (HPR, CXD)
FKL = (VPJ, SQN)
VRH = (BPN, JXR)
QQR = (KBH, LRQ)
RSC = (LQB, TNG)
NRQ = (DKD, CHG)
RHL = (NVQ, NNR)
QCH = (MGB, QQS)
CTS = (BFG, HDC)
KHJ = (NGN, LJC)
RGK = (MVL, FHG)
CCH = (LKP, TFT)
VSL = (FFH, PRR)
KQR = (RPT, MGJ)
LCN = (XTS, DCF)
TJN = (TMT, SNH)
CLT = (NBS, VNP)
JCJ = (QFS, RSJ)
BPN = (TJN, CVC)
FXG = (GLJ, XBV)
BGQ = (KQB, BLP)
RMR = (TVH, JHB)
CTM = (JLL, VFC)
KCF = (SLQ, FLH)
DHF = (XRN, BXN)
NDJ = (SSH, FPQ)
KSX = (XTS, DCF)
RPT = (DPL, QHP)
QJV = (TVB, LDC)
TNG = (BCT, MMQ)
FBK = (FVL, QVS)
MBJ = (XJQ, VGG)
CHD = (GJF, BPC)
LSF = (QHL, XNP)
SHN = (HQS, XPV)
TQR = (CDR, QGG)
GRA = (NNK, VNG)
RNS = (MBJ, PHD)
VFC = (GTJ, CBN)
PPC = (LFJ, KHL)
DDT = (STF, HNK)
NSD = (TCV, DDV)
VMC = (FDX, RLK)
QXS = (JPG, BHR)
PDF = (MBD, RSB)
QRV = (PCB, JNV)
QVJ = (KSX, LCN)
QDL = (GLH, SPJ)
MDJ = (GJJ, NVX)
HJP = (FVF, RLX)
FRS = (GLT, CDQ)
SBM = (FDD, XNG)
SMG = (CMQ, MGX)
TQJ = (NPH, CQS)
RHQ = (MJV, XTG)
FFD = (MSN, FKN)
CSS = (XQN, NNC)
PVD = (RQM, JJX)
GBS = (QRT, CCK)
JHH = (PNM, GHL)
QHL = (LLV, KRH)

2
2023/data/day9.expected Normal file
View file

@ -0,0 +1,2 @@
19199
13663968099527

12
2023/day8/rust/Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "rust_2023_08"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
aoc = { path = "../../../common/rust" }
either = "1.9.0"
itertools = "0.12.0"
petgraph = "0.6.4"

204
2023/day8/rust/src/main.rs Normal file
View file

@ -0,0 +1,204 @@
#![warn(clippy::pedantic)]
use std::{cmp::PartialEq, collections::HashMap, fmt::Debug, io::stdin, num::NonZeroUsize};
use either::Either;
use itertools::Itertools;
use petgraph::{
prelude::DiGraphMap,
visit::{Data, EdgeRef, GraphBase, IntoEdgesDirected, Walker},
Direction::Outgoing,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Step {
Left,
Right,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Edge {
Left,
Right,
Both,
}
impl Edge {
pub fn matches(self, s: Step) -> bool {
match (self, s) {
(Edge::Left, Step::Left) | (Edge::Right, Step::Right) | (Edge::Both, _) => true,
(Edge::Right, Step::Left) | (Edge::Left, Step::Right) => false,
}
}
}
struct StepsWalker<'a> {
current_node: &'a str,
step_idx: usize,
steps: Vec<Step>,
}
impl<'a> StepsWalker<'a> {
pub fn new(start: &'a str, steps: Vec<Step>) -> Self {
Self {
current_node: start,
steps,
step_idx: 0,
}
}
/// Resets the step sequence to the beginning.
pub fn reset_steps(&mut self) {
self.step_idx = 0;
}
/// Steps once. Returns `None` if all steps have been performed.
pub fn step<G>(&mut self, context: G) -> Option<&'a str>
where
G: IntoEdgesDirected + GraphBase<NodeId = &'a str> + Data<EdgeWeight = Edge>,
{
let step = self.steps.get(self.step_idx)?;
let mut targets = context
.edges_directed(self.current_node, Outgoing)
.filter_map(|e| e.weight().matches(*step).then_some(e.target()));
let next_node = targets.next()?;
assert_eq!(
targets.next(),
None,
"More than one {:?} edge from {:?}",
step,
self.current_node
);
self.current_node = next_node;
self.step_idx += 1;
Some(self.current_node)
}
pub fn find_end_positions<G>(mut self, context: G) -> impl Iterator<Item = usize>
where
G: IntoEdgesDirected + GraphBase<NodeId = &'a str> + Data<EdgeWeight = Edge>,
{
let mut seen = HashMap::new();
let mut pos = 1_usize;
loop {
while let Some(node) = self.step(context) {
let key = (node, self.step_idx - 1);
if let Some(&loop_start) = seen.get(&key) {
let period = NonZeroUsize::new(pos - loop_start).unwrap();
let mut ends: Vec<_> = seen
.into_iter()
.filter_map(|((node, _step_idx), pos)| node.ends_with('Z').then_some(pos))
.collect();
ends.sort_unstable();
let (initial, repeating) = ends
.into_iter()
.partition::<Vec<_>, _>(|&pos| pos < loop_start);
return initial.into_iter().chain((0_usize..).flat_map(move |n| {
repeating
.clone()
.into_iter()
.map(move |pos| pos + n * period.get())
}));
}
seen.insert(key, pos);
pos += 1;
}
self.reset_steps();
}
}
}
impl<'a, G> Walker<G> for StepsWalker<'a>
where
G: IntoEdgesDirected + GraphBase<NodeId = &'a str> + Data<EdgeWeight = Edge>,
{
type Item = &'a str;
fn walk_next(&mut self, context: G) -> Option<Self::Item> {
Some(if let Some(node) = self.step(context) {
node
} else {
self.reset_steps();
self.step(context).unwrap()
})
}
}
fn main() {
let mut lines = stdin().lines().map(Result::unwrap);
let steps: Vec<_> = lines
.next()
.unwrap()
.chars()
.map(|c| match c {
'L' => Step::Left,
'R' => Step::Right,
_ => unreachable!(),
})
.collect();
let lines: Vec<_> = lines.skip(1).collect();
let graph: DiGraphMap<_, _> = lines
.iter()
.flat_map(|l| {
let (from, to) = l.split_once(" = ").unwrap();
let (left, right) = to
.strip_prefix('(')
.unwrap()
.strip_suffix(')')
.unwrap()
.split_once(", ")
.unwrap();
if left == right {
Either::Left([(from, left, Edge::Both)])
} else {
Either::Right([(from, left, Edge::Left), (from, right, Edge::Right)])
}
.into_iter()
})
.collect();
let walker = StepsWalker::new("AAA", steps.clone());
println!(
"{}",
walker.iter(&graph).position(|n| n == "ZZZ").unwrap() + 1
);
let start_nodes = graph.nodes().filter(|n| n.ends_with('A'));
let mut end_positions: Vec<_> = start_nodes
.map(|start| {
StepsWalker::new(start, steps.clone())
.find_end_positions(&graph)
.peekable()
})
.collect();
let num_steps = loop {
let target = *end_positions[0].peek().unwrap();
for positions in &mut end_positions {
positions
.peeking_take_while(|&pos| pos < target)
.for_each(|_| {});
}
if end_positions
.iter_mut()
.map(|positions| positions.peek())
.all_equal()
{
break target;
}
end_positions[0].next().unwrap();
};
println!("{num_steps}");
}

10
Cargo.lock generated
View file

@ -669,6 +669,16 @@ dependencies = [
"strum 0.25.0",
]
[[package]]
name = "rust_2023_08"
version = "0.1.0"
dependencies = [
"aoc",
"either",
"itertools 0.12.0",
"petgraph",
]
[[package]]
name = "rustversion"
version = "1.0.14"

View file

@ -33,4 +33,5 @@ members = [
"2023/day5/rust",
"2023/day6/rust",
"2023/day7/rust",
"2023/day8/rust",
]