This commit is contained in:
Sugui 2023-12-08 09:47:43 +01:00
parent 63dda22b7f
commit 63b5391e61
5 changed files with 863 additions and 1 deletions

716
resources/input08.txt Normal file
View File

@ -0,0 +1,716 @@
LRLRLRRLRRRLRRRLRRRLRLRRRLRRRLRRRLLRLRRRLRLRRRLLRRRLRRLRRRLRRLRLRRRLRRRLRLRRLRRRLRRLRRRLRRLRLRRLRRRLRLRRLRRRLLRRRLRLRRLLLRLLRLRRLLRRRLLRLLRRLRLRRRLLLRLRRLRLRRLRRRLRRLLRRLLRLRRRLRRRLRLLLLRLLRLRLRLRRRLRRLRRLRLRRRLLRRLRLLRRLRLRRLRLRLRRLRRLLRLRRLLRLLRRRLLLRRRLRRLRLRRRLRRLRRRLRRLLLRRRR
QKX = (SQD, XTJ)
FKP = (JGJ, JPR)
VCQ = (XGB, SSS)
JSK = (LSQ, FFS)
LGF = (THC, RQQ)
HSQ = (TBN, XTK)
BGB = (CPJ, KVD)
DJD = (VBL, MKB)
XTJ = (TRB, TJN)
SNX = (KJN, SBX)
BMD = (BJH, XKX)
PRV = (BCM, MJT)
DNK = (FFS, LSQ)
FNR = (BMF, GFC)
SLS = (SQJ, DBC)
VBS = (NVV, KXT)
FTF = (JMM, LHK)
GTH = (BGR, HTH)
DJL = (KDH, QRQ)
JKN = (SVX, HTB)
KBR = (JSK, DNK)
KQF = (MSK, NSG)
FRX = (PXS, KBM)
SQC = (SRH, CFG)
PCV = (JPB, RHQ)
TND = (KLP, JLN)
DGQ = (DBL, CFH)
KQB = (VSG, DLB)
SMN = (DGL, KLT)
VTM = (GNQ, LSN)
RKJ = (RKK, FDK)
GPT = (NGQ, KCG)
BVQ = (RCF, QHP)
LHH = (HKF, VQC)
BPC = (KLP, JLN)
LDT = (RST, BMN)
TPN = (DLB, VSG)
JDX = (LTK, MTB)
GSB = (JBN, VHT)
MKB = (VCT, TMP)
BMN = (FDD, SSH)
CKX = (HMK, CHH)
LSV = (XKP, HNB)
QGN = (LQC, LVF)
BXB = (KPM, NFR)
PGL = (KXD, JVR)
CTS = (VTB, XFM)
BQM = (KLK, LVQ)
CHP = (KNF, GGX)
HBQ = (FHV, NBM)
BNT = (NGQ, KCG)
XSJ = (RDG, VNN)
STT = (KPB, PQV)
GMH = (DDN, MCB)
GRV = (GJQ, JMG)
DJB = (VSK, MSC)
PHQ = (LKF, TLK)
DGH = (VNG, GGP)
DHT = (HSQ, THB)
XJV = (VTM, JGC)
LGV = (HXV, JDL)
LNJ = (BNT, GPT)
RTV = (MKB, VBL)
RQQ = (DJL, BSC)
JDL = (LJT, HTF)
HST = (MSL, TCL)
TGG = (VSP, MNJ)
FFX = (KCF, CTQ)
VCT = (RMX, SVM)
SQD = (TJN, TRB)
FRN = (TGL, NFL)
MFL = (KLT, DGL)
GMG = (NLM, HXM)
NGB = (TFV, TXN)
CRK = (TND, BPC)
PGN = (RGD, NNK)
PRQ = (FLM, XGJ)
MXH = (SNM, JKM)
KLT = (MPS, XJV)
LJV = (KLK, LVQ)
CKS = (THB, HSQ)
DBF = (RHQ, JPB)
HSX = (PPC, FCR)
DSB = (CJV, BBG)
BSC = (QRQ, KDH)
CDG = (SLS, RXH)
DCJ = (KNR, VSX)
BFF = (KNF, GGX)
CRP = (MVK, NLT)
NNK = (NMP, GCR)
JBG = (MLP, BND)
MRQ = (XVQ, XVQ)
QJS = (QNG, QXX)
GBH = (JDQ, CQG)
QGM = (FTF, SDJ)
THS = (GFF, CTS)
PGJ = (JFX, BDV)
NLT = (BCK, JDX)
JMT = (MQT, SFJ)
JST = (PVC, TXB)
JHJ = (FGC, KGK)
DGG = (GMB, NJR)
VLM = (FQN, VHV)
CHH = (FQB, HSK)
TMP = (RMX, SVM)
QRQ = (LHH, BVN)
NBM = (DJC, TKB)
KGF = (DJP, CMM)
JVG = (LGS, RVP)
LKC = (VLG, TBC)
VQD = (XTJ, SQD)
CQB = (CHH, HMK)
XTK = (HJB, DVJ)
FLM = (TNP, GMG)
VPC = (QMC, NBG)
CGP = (KHF, CMS)
KBM = (TCP, DRV)
XFC = (CQH, KCK)
JVR = (XNG, SVK)
LBT = (CJP, PGJ)
JSF = (QJS, CRR)
VPS = (TGN, CJG)
KLG = (SNM, JKM)
XGL = (GGK, QQT)
HKG = (NFD, CCP)
PVN = (CRK, MRD)
RLT = (TMS, PRV)
HCB = (CDH, XSL)
MFX = (LTN, GMS)
QNZ = (QVP, XGL)
HTH = (BFR, MVX)
XGJ = (TNP, GMG)
DGJ = (QJS, CRR)
VGS = (NGB, BRK)
RKB = (GLL, CRS)
DBL = (MPB, GKD)
XNJ = (CBF, KRG)
JBN = (FFX, VLD)
CBD = (KHV, HCL)
QTM = (DGG, DDB)
DDB = (GMB, NJR)
HHF = (PGL, HXJ)
VXH = (CFK, NTC)
SRH = (NGC, MMP)
JMG = (BCR, GSN)
LBJ = (BGR, HTH)
QMC = (JBH, KBR)
KHF = (BTJ, DMS)
JPB = (BLP, DRK)
PQD = (PRV, TMS)
KXJ = (XMC, PDX)
KGC = (RGN, JVJ)
KTX = (KTT, GBH)
SFB = (TDX, JMT)
TXN = (PHP, CTJ)
FNN = (FKB, JNG)
KFM = (FLD, JTN)
QCP = (JTH, RHP)
CBT = (JMX, CRP)
RGB = (BMF, GFC)
PPL = (KXT, NVV)
MQT = (XPK, JBG)
VPH = (XMP, LNT)
LNP = (KXJ, VRJ)
XPK = (MLP, BND)
LTD = (RHF, LSV)
JFV = (PRP, DXS)
VRM = (RTX, BTX)
LHZ = (KJJ, FXQ)
TXP = (HLH, CCK)
CTB = (LKC, VNJ)
NSV = (JPD, XTF)
CRS = (QXK, SXM)
TBK = (FQM, FQM)
XKX = (PGX, KGT)
PHG = (THC, RQQ)
XLB = (JLX, PDR)
FQB = (VPS, KHB)
SVX = (CRV, JQL)
QVL = (SSS, XGB)
DPM = (MBV, CXJ)
GCB = (NKN, DSB)
CFK = (TFX, CTB)
HMJ = (DVR, DVX)
GTF = (SSN, KVX)
FTV = (CFG, SRH)
KGX = (PNC, GJM)
TVD = (MXP, FCV)
JRD = (HFH, HFT)
RGD = (GCR, NMP)
LLC = (TGL, TGL)
NSG = (CDQ, LTD)
DSC = (NFR, KPM)
GQJ = (JTN, FLD)
GJG = (HLH, CCK)
MDP = (KHV, HCL)
VXS = (DDF, DVK)
GRG = (MPP, HKQ)
TXB = (CLQ, GVQ)
DXS = (PMJ, RRR)
GMS = (JDT, HQX)
BDV = (TNK, XLB)
XTF = (FBS, SFB)
GKD = (GMH, LHM)
SSH = (FPS, PTV)
HJB = (CTL, LMX)
XLD = (QMT, BVQ)
SDK = (DBN, JFL)
XSM = (VQD, QKX)
TRB = (PQR, GRG)
LDQ = (HMJ, BFL)
JQT = (VLM, LXL)
GMM = (KBM, PXS)
JFX = (TNK, XLB)
XSL = (DQQ, TKF)
KNN = (PPB, KTX)
NJK = (KGN, LFP)
RHP = (PKJ, JVG)
VBL = (VCT, TMP)
KXD = (XNG, SVK)
DLB = (FRX, GMM)
BFR = (VXH, TSR)
CJP = (BDV, JFX)
LTK = (MCT, RCX)
JMX = (MVK, NLT)
DNC = (SDJ, FTF)
XMP = (XSJ, TDR)
GNP = (GJS, XFC)
RSJ = (GJM, PNC)
LVQ = (QGX, JST)
KRG = (LVH, HXP)
VDV = (QRK, NBT)
NGC = (SMN, MFL)
MVG = (PVN, DRT)
GLH = (JMG, GJQ)
BGR = (MVX, BFR)
XFM = (BFF, CHP)
NHG = (BQR, BHN)
MRD = (BPC, TND)
NLF = (RVB, FPM)
CMS = (BTJ, DMS)
NBR = (RGD, NNK)
NCK = (DSC, BXB)
DJM = (VSK, MSC)
SFJ = (XPK, JBG)
FCS = (PGL, HXJ)
XKP = (TXG, GKK)
LVH = (DCJ, QNJ)
JBD = (NNX, DTF)
DJP = (XMX, QLG)
CRV = (CFR, PGD)
FSR = (VHT, JBN)
MBV = (PJN, JHJ)
KCK = (TXP, GJG)
JVJ = (XNJ, LHJ)
NKX = (XMP, LNT)
FGC = (VGF, HKG)
DCX = (PVN, DRT)
RJJ = (RLT, PQD)
HFD = (XVQ, XSX)
LFH = (MMD, MFD)
KHV = (KQF, PFP)
VKQ = (RGB, FNR)
DDF = (RCT, QRX)
LHJ = (KRG, CBF)
GSP = (NNX, DTF)
FLQ = (LNP, RTL)
FDD = (FPS, PTV)
VSS = (SLS, RXH)
CTL = (DFG, QCP)
CSS = (PPB, KTX)
MNC = (QBB, HLS)
PHP = (GQC, DLP)
MHD = (MLL, SJV)
LPK = (NFJ, NCK)
RFL = (KKM, LNJ)
LSQ = (CDG, VSS)
NDG = (VSP, VSP)
NKB = (XCN, SNX)
PQR = (HKQ, MPP)
MMP = (SMN, MFL)
QGX = (TXB, PVC)
CRM = (STS, NFQ)
TFX = (VNJ, LKC)
STX = (LPM, MNC)
VLG = (DHD, SJK)
KVD = (MVT, BMB)
MSK = (LTD, CDQ)
FXQ = (DJB, DJM)
BRM = (TCL, MSL)
TKB = (KFM, GQJ)
XRT = (XTV, JHM)
BLT = (GQV, ZZZ)
SDJ = (LHK, JMM)
RMQ = (HXV, JDL)
FQN = (SJD, VKQ)
BTX = (RSJ, KGX)
JTH = (PKJ, JVG)
XMX = (VXS, XJD)
RDT = (PBH, DQC)
DTN = (LXL, VLM)
VXR = (CBD, MDP)
LFG = (RMQ, LGV)
HMK = (FQB, HSK)
TFV = (PHP, CTJ)
SLH = (LTN, LTN)
PBS = (NBM, FHV)
VNN = (QCF, XRT)
SBX = (HLX, CBT)
VBK = (CKT, GQF)
GFF = (VTB, XFM)
SDP = (DXS, PRP)
NFR = (TFT, QGN)
LDX = (QTM, DQN)
LJT = (HRJ, RKJ)
FDV = (NSV, QQF)
FDK = (VPH, NKX)
GBQ = (MBV, CXJ)
MXP = (TFN, BXT)
JDQ = (XHX, VDV)
JLX = (SNT, BDR)
TCL = (DFS, GVD)
DRK = (SLH, MFX)
KNB = (SDK, HLJ)
GMB = (DQH, NHG)
RVP = (GTH, LBJ)
BLP = (SLH, MFX)
DJC = (GQJ, KFM)
GFC = (RKB, QBR)
TLK = (RFL, TJS)
HTB = (CRV, JQL)
KRV = (JLT, BSQ)
PCQ = (FXQ, KJJ)
KCF = (PLG, CQR)
SVM = (GLT, VGS)
FRD = (RGN, JVJ)
PPB = (KTT, GBH)
CCT = (XSN, VPC)
JSJ = (RMQ, LGV)
TDX = (MQT, SFJ)
DRT = (MRD, CRK)
NFL = (XSM, FBZ)
GMX = (XLD, RKV)
NHB = (SJV, MLL)
THB = (TBN, XTK)
FTR = (PPC, FCR)
QRX = (GTF, VCX)
CXJ = (JHJ, PJN)
FCR = (RXX, STT)
LQA = (VQD, QKX)
LVV = (XFC, GJS)
RVR = (FSR, GSB)
KDH = (BVN, LHH)
CJV = (KLG, MXH)
MNJ = (VXR, QXZ)
HKQ = (QGM, DNC)
BND = (CHS, PHQ)
DRV = (NGD, VRM)
XTV = (RXK, LPK)
MFD = (LLC, FRN)
CQH = (TXP, GJG)
XSX = (PCQ, LHZ)
SGA = (XGL, QVP)
VSG = (FRX, GMM)
RVG = (DBL, CFH)
GGP = (VBS, PPL)
NTC = (TFX, CTB)
HCL = (PFP, KQF)
JLF = (XSN, VPC)
KGT = (RHH, NNT)
MJT = (JSF, DGJ)
PLG = (NLF, TQN)
HXM = (BHM, FNN)
MVK = (JDX, BCK)
TFT = (LVF, LQC)
CJK = (MMD, MFD)
TNP = (NLM, HXM)
BHM = (JNG, FKB)
CQK = (SVD, KVN)
BXT = (GMX, MGB)
TTR = (DLC, LDT)
NQM = (LHX, LDX)
VGF = (NFD, CCP)
SVK = (VCQ, QVL)
CPJ = (MVT, BMB)
FLD = (JKN, MBD)
RKV = (QMT, BVQ)
HGH = (SDP, JFV)
AAA = (FCS, HHF)
QLG = (VXS, XJD)
PFP = (MSK, NSG)
KTT = (CQG, JDQ)
BMB = (FRD, KGC)
NNT = (GBL, FBT)
LGS = (LBJ, GTH)
XVR = (KGN, LFP)
RTL = (VRJ, KXJ)
FTS = (KDB, VVN)
MNP = (BFL, HMJ)
MLF = (FSR, GSB)
PJN = (KGK, FGC)
HNB = (GKK, TXG)
GNQ = (BRM, HST)
SXM = (JRD, FDS)
RXX = (KPB, PQV)
JMM = (GSP, JBD)
DLP = (PHG, LGF)
XCN = (KJN, SBX)
DBC = (DPM, GBQ)
TCP = (NGD, VRM)
XHX = (NBT, QRK)
PDR = (SNT, BDR)
VCJ = (NSV, QQF)
DLM = (CKX, CQB)
KXT = (PBS, HBQ)
SSS = (TPN, KQB)
JMR = (SNX, XCN)
QQF = (JPD, XTF)
GVQ = (FLQ, RQG)
NFJ = (BXB, DSC)
DQN = (DGG, DDB)
MSC = (RDT, DVC)
JBH = (DNK, JSK)
BVN = (HKF, VQC)
DTF = (LVP, HCB)
JNG = (CRM, BCH)
HRJ = (RKK, FDK)
BTJ = (DLM, LFM)
LSN = (HST, BRM)
TMS = (BCM, MJT)
XGB = (TPN, KQB)
KGK = (VGF, HKG)
MVT = (KGC, FRD)
BJA = (CBD, MDP)
QBB = (RVG, DGQ)
PPC = (RXX, STT)
JKM = (CBS, JVV)
FBT = (QPF, CQK)
TBC = (DHD, SJK)
RXR = (CGP, FJQ)
TGL = (XSM, XSM)
LQC = (MLF, RVR)
HTF = (RKJ, HRJ)
GJM = (XVR, NJK)
BFL = (DVX, DVR)
LHK = (JBD, GSP)
HQQ = (QLJ, STX)
DSP = (RLT, PQD)
BCR = (KJM, FTS)
NBT = (BMD, THN)
VLD = (KCF, CTQ)
DVJ = (LMX, CTL)
CCP = (RJJ, DSP)
HFT = (LJV, BQM)
QXX = (MRQ, HFD)
KHB = (CJG, TGN)
FHV = (DJC, TKB)
VQC = (RFG, TVD)
QHP = (THS, QTN)
NKN = (CJV, BBG)
LVF = (MLF, RVR)
NLM = (FNN, BHM)
PRP = (RRR, PMJ)
FJQ = (KHF, CMS)
HLH = (GST, VXQ)
CBF = (LVH, HXP)
LHX = (QTM, DQN)
KPB = (NJF, RXR)
HSK = (KHB, VPS)
PKJ = (LGS, RVP)
RHF = (XKP, HNB)
SNT = (CJB, VPN)
PGD = (NTQ, VJK)
JHM = (LPK, RXK)
VLF = (QLJ, STX)
SJK = (KNB, TRL)
TNK = (PDR, JLX)
NNX = (HCB, LVP)
CDH = (DQQ, TKF)
RMX = (GLT, VGS)
BHN = (DBB, HQJ)
VVC = (LDX, LHX)
QXZ = (MDP, CBD)
MQL = (NKN, DSB)
NJR = (NHG, DQH)
JFL = (RTV, DJD)
GVD = (NBR, PGN)
GBL = (QPF, CQK)
QCF = (XTV, JHM)
TXG = (DHT, CKS)
DDN = (RXF, JXX)
LFP = (MVG, DCX)
NVV = (HBQ, PBS)
PVC = (CLQ, GVQ)
KVX = (FTR, HSX)
JTN = (MBD, JKN)
CLQ = (RQG, FLQ)
MPP = (QGM, DNC)
CBS = (VBK, XKT)
BCK = (MTB, LTK)
FFS = (VSS, CDG)
QVP = (QQT, GGK)
VSX = (JLF, CCT)
CRR = (QNG, QXX)
TRL = (HLJ, SDK)
VRJ = (XMC, PDX)
HLJ = (DBN, JFL)
THC = (DJL, BSC)
JLN = (BRG, HGH)
FDS = (HFH, HFT)
NGD = (RTX, BTX)
DQQ = (JMR, NKB)
KDB = (PRQ, KRL)
QBR = (CRS, GLL)
VSP = (VXR, VXR)
DBN = (RTV, DJD)
KJJ = (DJB, DJM)
QTN = (CTS, GFF)
DVK = (QRX, RCT)
DBB = (MHD, NHB)
RCX = (LBT, RSV)
GSN = (FTS, KJM)
CDQ = (RHF, LSV)
CMM = (QLG, XMX)
HFH = (LJV, BQM)
QLJ = (MNC, LPM)
HXV = (HTF, LJT)
LTN = (JDT, JDT)
GVR = (XGL, QVP)
RDG = (QCF, XRT)
BJH = (PGX, KGT)
DJK = (FQM, BLT)
RKK = (NKX, VPH)
RXH = (DBC, SQJ)
TFN = (MGB, GMX)
XKT = (CKT, GQF)
ZZZ = (HHF, FCS)
KVN = (VVC, NQM)
XSN = (NBG, QMC)
DFS = (NBR, PGN)
CHS = (LKF, TLK)
HXJ = (KXD, JVR)
SJD = (RGB, FNR)
CQR = (NLF, TQN)
MMD = (LLC, LLC)
RTX = (KGX, RSJ)
RQG = (RTL, LNP)
DVR = (GCB, MQL)
MCT = (LBT, RSV)
MTB = (MCT, RCX)
RGN = (XNJ, LHJ)
VJK = (FDV, VCJ)
CFR = (NTQ, VJK)
RST = (SSH, FDD)
MSL = (GVD, DFS)
DGL = (XJV, MPS)
FCV = (BXT, TFN)
KCG = (TTR, GDH)
GJS = (KCK, CQH)
HQX = (GVR, QNZ)
CFG = (MMP, NGC)
CJG = (BGB, QVG)
RSV = (PGJ, CJP)
VTB = (BFF, CHP)
BDR = (VPN, CJB)
LPM = (QBB, HLS)
VSK = (RDT, DVC)
PBH = (LDQ, MNP)
CFH = (MPB, GKD)
DQH = (BHN, BQR)
KPM = (TFT, QGN)
TBN = (HJB, DVJ)
JDT = (GVR, GVR)
GDH = (DLC, LDT)
VNJ = (TBC, VLG)
PDX = (JSJ, LFG)
DLC = (RST, BMN)
CHG = (DJP, CMM)
JLT = (DGH, DGH)
MVX = (TSR, VXH)
GGX = (NDG, TGG)
RCT = (VCX, GTF)
MCB = (RXF, JXX)
LNT = (TDR, XSJ)
GST = (PQN, PQN)
CTQ = (CQR, PLG)
LVP = (XSL, CDH)
DQC = (LDQ, MNP)
VCX = (KVX, SSN)
BQR = (DBB, HQJ)
TSR = (CFK, NTC)
SFC = (DTN, JQT)
THN = (BJH, XKX)
MBD = (HTB, SVX)
NFD = (DSP, RJJ)
TQN = (FPM, RVB)
SVA = (FXQ, KJJ)
BRG = (JFV, SDP)
FQM = (GQV, GQV)
GLL = (SXM, QXK)
NJF = (FJQ, CGP)
VPN = (GLH, GRV)
PMJ = (FTV, SQC)
QQT = (SFC, QVB)
SNM = (CBS, JVV)
JXX = (TBK, DJK)
HLS = (DGQ, RVG)
RHH = (FBT, GBL)
VXQ = (PQN, KRV)
DVX = (GCB, MQL)
GKK = (DHT, CKS)
SJV = (DBF, PCV)
BRK = (TFV, TXN)
MLL = (DBF, PCV)
GGK = (SFC, QVB)
HLX = (CRP, JMX)
FKB = (BCH, CRM)
GQC = (PHG, LGF)
QXK = (FDS, JRD)
HXP = (QNJ, DCJ)
SVD = (NQM, VVC)
FBS = (TDX, JMT)
QVB = (JQT, DTN)
QMT = (RCF, QHP)
PNC = (NJK, XVR)
RXK = (NFJ, NCK)
GJQ = (GSN, BCR)
KRL = (FLM, XGJ)
QPF = (SVD, KVN)
KNF = (NDG, NDG)
GQF = (KGF, CHG)
KLP = (BRG, HGH)
XJD = (DDF, DVK)
GFA = (VNG, GGP)
TGN = (QVG, BGB)
NGQ = (GDH, TTR)
CCK = (GST, VXQ)
MPB = (GMH, LHM)
CJB = (GLH, GRV)
BBG = (KLG, MXH)
CTJ = (DLP, GQC)
JPD = (SFB, FBS)
VHV = (VKQ, SJD)
NTQ = (VCJ, FDV)
RVB = (CSS, KNN)
GLT = (NGB, BRK)
DHD = (TRL, KNB)
TDR = (VNN, RDG)
FBZ = (QKX, VQD)
PQN = (JLT, JLT)
PQV = (NJF, RXR)
RHQ = (BLP, DRK)
QRK = (THN, BMD)
KNR = (CCT, JLF)
TJN = (PQR, GRG)
BSQ = (DGH, BRZ)
MPS = (JGC, VTM)
BMF = (RKB, QBR)
QNJ = (VSX, KNR)
STS = (CJK, LFH)
NMP = (HQQ, VLF)
HKF = (TVD, RFG)
FPM = (KNN, CSS)
PXS = (DRV, TCP)
TJS = (LNJ, KKM)
LFM = (CQB, CKX)
SSN = (FTR, HSX)
CQG = (XHX, VDV)
QVG = (CPJ, KVD)
BCH = (STS, NFQ)
NBG = (KBR, JBH)
XMC = (JSJ, LFG)
LMX = (QCP, DFG)
RXF = (TBK, TBK)
MLP = (CHS, PHQ)
JVV = (VBK, XKT)
MGB = (RKV, XLD)
KKM = (BNT, GPT)
GCR = (HQQ, VLF)
LHM = (DDN, MCB)
XNG = (QVL, VCQ)
FPS = (FKP, LGK)
BRZ = (GGP, VNG)
JQL = (PGD, CFR)
RRR = (FTV, SQC)
CKT = (KGF, CHG)
VVN = (KRL, PRQ)
BCM = (DGJ, JSF)
PGX = (NNT, RHH)
DFG = (JTH, RHP)
JGC = (LSN, GNQ)
RCF = (THS, QTN)
DMS = (LFM, DLM)
VHT = (FFX, VLD)
LGK = (JGJ, JPR)
LKF = (TJS, RFL)
KGN = (MVG, DCX)
KLK = (QGX, JST)
KJN = (HLX, CBT)
LXL = (VHV, FQN)
RFG = (FCV, MXP)
DVC = (PBH, DQC)
PTV = (FKP, LGK)
KJM = (VVN, KDB)
SQJ = (DPM, GBQ)
GQV = (FCS, HHF)
QNG = (MRQ, MRQ)
HQJ = (MHD, NHB)
VNG = (VBS, PPL)
NFQ = (CJK, LFH)
TKF = (NKB, JMR)
JGJ = (GNP, LVV)
XVQ = (PCQ, PCQ)
JPR = (LVV, GNP)

View File

@ -0,0 +1,90 @@
package sugui.day08;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import sugui.util.Pair;
public class Day08 {
public static Path inputPath = Paths.get("resources/input08.txt");
enum Instruction {
LEFT, RIGHT
}
private record Network(List<Instruction> instructions, Map<String, Pair<String, String>> nodes) {
}
public static void main(String[] args) throws IOException {
var input = Files.readString(inputPath);
var firstResult = getFirstPuzzleResult(input);
var secondResult = getSecondPuzzleResult(input);
System.out.println("First result: " + firstResult);
System.out.println("Second result: " + secondResult);
}
private static Network parse(String input) {
String[] splittedInput = input.split("\n\n");
List<Instruction> instructions = splittedInput[0].chars()
.mapToObj(c -> c == 'L' ? Instruction.LEFT : Instruction.RIGHT).collect(Collectors.toList());
Map<String, Pair<String, String>> nodes = new HashMap<>();
Pattern nodeName = Pattern.compile("(\\w+) = \\((\\w+), (\\w+)\\)");
for (String line : splittedInput[1].split("\n")) {
Matcher matcher = nodeName.matcher(line);
matcher.find();
String mainNode = matcher.group(1);
String leftNode = matcher.group(2);
String rightNode = matcher.group(3);
nodes.put(mainNode, new Pair<>(leftNode, rightNode));
}
return new Network(instructions, nodes);
}
public static String getFirstPuzzleResult(String input) {
Network network = parse(input);
int hops = hops(network, "AAA", "ZZZ");
return Integer.toString(hops);
}
private static int hops(Network network, String nodeName, String end) {
String currNode = nodeName;
int hops = 0;
while (!currNode.endsWith(end)) {
Instruction instruction = network.instructions.get(hops % network.instructions.size());
currNode = instruction == Instruction.LEFT ? network.nodes.get(currNode)._1()
: network.nodes.get(currNode)._2();
hops++;
}
return hops;
}
private static long gcd(long x, long y) {
return y == 0 ? x : gcd(y, x % y);
}
private static long mcm(long x, long y) {
return (x * y) / gcd(x, y);
}
public static String getSecondPuzzleResult(String input) {
Network network = parse(input);
var result = network.nodes.keySet().stream().filter(node -> node.endsWith("A"))
.map(node -> (long)hops(network, node, "Z")).reduce((ac, i) -> mcm(ac, i));
return Long.toString(result.get());
}
}

View File

@ -1,4 +1,4 @@
package sugui;
package sugui.dayXX;
import java.io.IOException;
import java.nio.file.Files;

View File

@ -0,0 +1,54 @@
package sugui;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import sugui.day08.Day08;
import sugui.dayXX.DayXX;
/**
* Unit test for simple App.
*/
public class Day08Test {
public static String firstBasicInput = """
RL
AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)
""";
public static String secondBasicInput = """
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)
""";
public static String firstBasicResult = "2";
public static String secondBasicResult = "6";
@Test
public void firstBasicCase() throws IOException {
String actualResult = Day08.getFirstPuzzleResult(firstBasicInput);
assertEquals(firstBasicResult, actualResult);
}
@Test
public void secondBasicCase() throws IOException {
String actualResult = Day08.getSecondPuzzleResult(secondBasicInput);
assertEquals(secondBasicResult, actualResult);
}
}

View File

@ -6,6 +6,8 @@ import java.io.IOException;
import org.junit.Test;
import sugui.dayXX.DayXX;
/**
* Unit test for simple App.
*/