This commit is contained in:
Savanni D'Gerinel 2023-12-19 20:52:27 -05:00
parent 90396f7fd1
commit febbf4c709
6 changed files with 954 additions and 11 deletions

62
2023/Cargo.lock generated
View File

@ -2,11 +2,22 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "aoc-2023"
version = "0.1.0"
dependencies = [
"nom",
"pariter",
"regex",
]
[[package]]
@ -100,6 +111,12 @@ version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "memchr"
version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "memoffset"
version = "0.9.0"
@ -109,6 +126,22 @@ dependencies = [
"autocfg",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
@ -130,6 +163,35 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "regex"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "scopeguard"
version = "1.2.0"

View File

@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nom = "7.1.3"
pariter = { version = "0.5" }
regex = "1.10.2"

716
2023/data/day8.txt Normal file
View File

@ -0,0 +1,716 @@
LRLRLRRLRRLRLRRRLRRLRLRRLLLRRRLRRRLLRRLRRRLRRRLRRLRRLRRRLRRLRLRLRRRLRRLRRLLRRRLLRLRRRLRRRLRRLRRRLRRLLRLLRRRLRRLRLRRRLRLRLRRRLLRLRRLLRRRLRRRLRLRRLLRRLRLRRLRRRLRLLRRRLRRRLLRLLRLLRRRLRLRLRLRLRRLRRLRLRRRLLLRLLRRRLRRLLRLRLRRRLLRLRRRLLRRLRRLRLRLRLRRLRRLRRRLRRRLRRLRRLRRRLRLRRRLRLRRRR
FTD = (QRN, JJC)
LMR = (KND, NTK)
XMV = (RGS, CGP)
KSC = (TGM, CPQ)
MTP = (BBX, TVN)
MSR = (GGL, GGL)
LGX = (DTT, PKP)
NLV = (DDK, MCH)
KSF = (DQS, CTM)
BFB = (JQD, CMG)
TGH = (FVM, TNT)
SJG = (XVB, LKD)
XTK = (XHD, JTP)
XVK = (RBH, JGS)
RFS = (FPG, LTD)
QTQ = (QMH, QDB)
LHS = (CRH, RRQ)
RJP = (HSR, TBP)
CKS = (XCC, XCC)
HGP = (VKR, GSB)
GNM = (GSM, KJL)
JRN = (MGQ, VLL)
BBG = (QPL, KKN)
RNV = (DTC, RCP)
PJJ = (CDX, THL)
KNF = (GXG, DCN)
XNL = (QKC, FBF)
QJS = (SSK, GNR)
TNH = (HDQ, KVK)
CXT = (SVL, DQN)
NKV = (RPS, KPG)
NPQ = (TTT, TRL)
TVX = (HQV, MXC)
PCB = (PRX, KCT)
JND = (KKS, DNF)
MKB = (TQC, HCQ)
JXH = (XLF, TVX)
KPG = (CCC, HHJ)
PRN = (RVT, CSS)
TLQ = (KNF, JHM)
SJV = (SGS, TBH)
DLM = (JQH, DKV)
JHS = (JKJ, SVT)
XLG = (HVD, JND)
CPV = (DDS, RGG)
TTP = (PSS, MDJ)
LPC = (QSP, SDT)
BPJ = (GGK, NSN)
FPL = (KKL, LPS)
TNC = (XXB, GQP)
PRQ = (SVN, HDB)
KKN = (LCV, MGD)
QNM = (RLJ, NHT)
GMB = (CHK, VLS)
KFG = (RKJ, DMR)
FML = (HCJ, BDS)
DRJ = (BSF, BDF)
FBB = (DLR, FQN)
VFQ = (THC, MHG)
PFF = (TNT, FVM)
LVV = (VLG, DHP)
CCC = (MSL, KJP)
HMS = (FMQ, KBV)
FND = (TNH, CCL)
GHK = (JFS, TQP)
TRJ = (SSN, KSC)
XKR = (BMX, DLS)
TKQ = (DSB, LFF)
HBX = (HQD, XJF)
RCF = (MVK, BPC)
MFR = (NDL, XBG)
FDF = (HFR, JSB)
DBH = (XLQ, DRJ)
BCP = (XGX, GMR)
CNX = (BFB, XBS)
PTQ = (XNN, BMK)
HJS = (CCL, TNH)
NQH = (HPR, DTN)
RTL = (FVG, SHS)
CDV = (XHD, JTP)
XNN = (KFG, NFQ)
RPS = (CCC, HHJ)
TVN = (SXH, HMK)
CBN = (PKP, DTT)
DCN = (RCF, BQC)
SBD = (XMV, SSF)
THV = (DLC, RHV)
SXG = (LMJ, SBD)
JVK = (VKS, BHS)
XTV = (PSC, HXN)
BJN = (LSJ, NSX)
HQV = (FSR, RNV)
SSK = (JNG, BBG)
FRJ = (CNX, CTF)
VNH = (HJS, FND)
QGT = (VKS, BHS)
VRH = (HJS, FND)
PBD = (PRN, HLR)
DNJ = (SXG, QCF)
PRX = (JBS, JSH)
GCV = (BVC, TXS)
GQP = (DMX, CDS)
MHG = (DNR, BVH)
BSN = (BDS, HCJ)
BKQ = (RQB, RQB)
LRT = (DPT, KSF)
VTL = (XRF, VCB)
DQN = (CSP, XBF)
LXN = (CNC, MDL)
XVQ = (NLJ, SBJ)
VBQ = (MDM, BTC)
HTB = (KGJ, KQK)
NKJ = (LTM, MNJ)
CBT = (KSC, SSN)
HKL = (JBC, NQN)
TGN = (VXR, JQG)
MDJ = (GTC, NJF)
CGP = (QRH, SJB)
LLV = (RBH, JGS)
DPT = (DQS, CTM)
NNJ = (TVX, XLF)
XHD = (XNL, VGB)
NVF = (TKL, HXJ)
SGS = (SNP, CKJ)
RCP = (GGF, NCK)
VXR = (XJV, VXX)
VRQ = (QKH, DHT)
KKS = (PTH, LXJ)
KJT = (TNC, HVV)
LMP = (VLG, VLG)
TKL = (KMV, XPB)
CVC = (VVD, PRQ)
SKB = (RTL, DRK)
GSM = (XKK, JPX)
LKD = (NDB, XQN)
HRQ = (PRQ, VVD)
LKH = (THL, CDX)
PXL = (TLV, FRX)
HXJ = (XPB, KMV)
DTC = (GGF, NCK)
DNK = (FBS, FRP)
BSB = (HML, BGT)
VHM = (CRH, RRQ)
VCR = (FML, BSN)
LQB = (GGN, GSS)
SJL = (QSP, SDT)
HBN = (QRJ, LXR)
BTD = (CSX, FRQ)
QPP = (KNP, VRQ)
LDD = (BVC, TXS)
KDV = (VRG, TDF)
MSM = (NVJ, SJG)
KGX = (BBV, SPB)
HDP = (HKC, RFB)
CNR = (DTF, CBL)
DDK = (NBR, SRM)
XBF = (DGL, FSC)
HDB = (FKJ, BPD)
FVM = (XDM, QMF)
SCX = (KKL, LPS)
XHR = (FML, BSN)
VTB = (GPN, HDP)
DJC = (FJP, TQJ)
PTH = (KXV, KJK)
DPG = (SNG, BPJ)
KLT = (PBD, LSG)
BDN = (FBR, HBN)
DPF = (BNM, JVM)
JHM = (DCN, GXG)
TBP = (PLR, DXS)
RGS = (QRH, SJB)
RMA = (HDD, CMP)
MQZ = (JQM, VVG)
XGX = (QTQ, LLX)
KJX = (JND, HVD)
RXM = (SKB, HSG)
LCG = (VGL, LDT)
VDK = (JKH, FTD)
HRB = (GPN, HDP)
ZZZ = (LTD, FPG)
VGG = (CML, JQS)
FRX = (FSP, VBQ)
JTP = (VGB, XNL)
DHT = (KJT, PLS)
CCL = (KVK, HDQ)
BBC = (DLS, BMX)
CTJ = (KCQ, LNP)
PHJ = (DQP, TLQ)
SVL = (XBF, CSP)
NXA = (RVD, QNM)
NSQ = (PDC, DKQ)
SVK = (MVS, HTG)
BVH = (NQH, VHL)
DLX = (KBR, VPV)
SCD = (RHV, DLC)
DRK = (FVG, SHS)
BDS = (MCL, FLR)
PNX = (SPB, BBV)
QMC = (TLP, GJX)
XKB = (BPM, SQD)
PSS = (GTC, NJF)
VXK = (GCG, DRD)
MFC = (PFF, TGH)
RMB = (NDK, PMJ)
RGG = (CGV, XVQ)
JNC = (BHK, BFQ)
BCB = (VLL, MGQ)
BCR = (HTB, TLT)
RHG = (MKB, XTQ)
XXR = (GMB, QRX)
XJF = (JNC, QBK)
PLR = (TTG, TTG)
RDQ = (QLV, LKR)
QQK = (LQB, JDB)
VCB = (NVF, GLR)
RPP = (JGM, PSX)
KBV = (BTB, VHG)
QPM = (RNB, GBC)
CSS = (QLH, BTR)
GBC = (VKX, NSQ)
JJJ = (SHQ, PMS)
CDJ = (HQK, BKR)
THL = (HDM, RHG)
FGK = (QPM, JSC)
HDQ = (CBT, TRJ)
TLP = (STK, NPL)
GKV = (VKR, GSB)
CNC = (BSB, TNB)
QSP = (NGF, HXM)
PRV = (HDD, CMP)
SQD = (BJN, MDQ)
DKQ = (PBX, XTV)
MXK = (JFS, TQP)
TGM = (NPQ, PHS)
HBD = (LTM, MNJ)
BSF = (NCQ, KLT)
GXG = (BQC, RCF)
HKV = (JGM, JGM)
QHK = (FPL, SCX)
SXH = (SVS, MSM)
PLS = (HVV, TNC)
XJV = (VTB, HRB)
HQK = (VNH, VRH)
GGL = (RPG, RPG)
RQB = (CKS, CKS)
NCQ = (LSG, PBD)
VPQ = (FRJ, BNT)
RVD = (RLJ, NHT)
HTG = (DGF, GCQ)
KMX = (LCH, SCG)
RMD = (JVK, QGT)
FKR = (RXM, MTN)
VNB = (KBR, VPV)
LSG = (PRN, HLR)
CTM = (BKQ, RJG)
TNB = (HML, BGT)
SRM = (HKV, RPP)
MSL = (XHR, VCR)
SQX = (SGL, NQV)
MGQ = (LPC, SJL)
GCG = (NJX, KSR)
HTX = (HBN, FBR)
NJX = (RGL, PND)
SGZ = (PNX, KGX)
XLF = (HQV, MXC)
HQG = (CKV, HKL)
BBV = (NXM, HMS)
QRJ = (GPS, LKK)
CKF = (XCC, SGZ)
HKC = (NNJ, JXH)
SHM = (NKV, TCS)
SVS = (NVJ, SJG)
SSR = (GGL, HVG)
NVJ = (XVB, LKD)
QGP = (QHK, FJH)
FRQ = (FBP, TKQ)
KMV = (CPV, SMX)
LSJ = (LCP, SRJ)
CSM = (HKN, DJC)
JRK = (BKR, HQK)
RNB = (VKX, NSQ)
FSR = (RCP, DTC)
DKN = (FNQ, TCT)
MVK = (XKR, BBC)
NDG = (DKN, NFN)
MVS = (DGF, GCQ)
GDA = (KGX, PNX)
DQP = (KNF, JHM)
XPB = (SMX, CPV)
VXX = (HRB, VTB)
JSC = (GBC, RNB)
VLS = (NDC, RTM)
JFS = (PVF, KJJ)
DBK = (LFN, CFJ)
MTN = (SKB, HSG)
SDK = (QQK, NSR)
GMR = (LLX, QTQ)
VBH = (FRJ, BNT)
GPN = (HKC, RFB)
FSC = (KDK, FDF)
TKM = (CXB, MTP)
VLG = (RFS, RFS)
RFB = (NNJ, JXH)
QHD = (QRX, GMB)
GSS = (VMV, DFT)
MCF = (QJS, TDX)
DTF = (VQR, LFP)
XHM = (CTG, TND)
JQH = (BCP, KSH)
SBM = (MTN, RXM)
KGJ = (SVK, SCT)
TDP = (MCD, CQG)
BNM = (RQS, JJJ)
LTD = (HBX, THT)
TQJ = (SJV, MXJ)
BPM = (BJN, MDQ)
THT = (XJF, HQD)
QMF = (XKB, GST)
HQD = (QBK, JNC)
NHS = (VXR, JQG)
THX = (TKM, TKM)
GST = (SQD, BPM)
QJD = (CKV, HKL)
VLL = (LPC, SJL)
KXD = (TND, CTG)
FBS = (KDV, NVM)
KVK = (TRJ, CBT)
QMH = (RMV, TTP)
RVJ = (KXQ, MCF)
HXN = (BMM, TGX)
LFF = (DPF, CBF)
KJL = (XKK, JPX)
QQM = (VHM, LHS)
LQQ = (LFV, GNM)
THC = (BVH, DNR)
QRX = (VLS, CHK)
NDK = (FKR, SBM)
FKJ = (LRT, PDN)
SJM = (XNN, BMK)
DRD = (KSR, NJX)
JBC = (XTK, CDV)
JPX = (NHH, PHJ)
SNG = (GGK, NSN)
RBN = (NFN, DKN)
MSH = (JQH, DKV)
RTM = (VGJ, SKL)
KNP = (QKH, DHT)
TDX = (GNR, SSK)
SCC = (LFV, GNM)
GKL = (GDM, KKR)
BPD = (LRT, PDN)
JFJ = (TGP, NLR)
VMV = (XPQ, TDP)
RBH = (QQM, HRD)
BNT = (CTF, CNX)
JSP = (NDK, PMJ)
FNV = (FTD, JKH)
HKN = (TQJ, FJP)
SGL = (DBH, XHC)
VVG = (MDT, PCB)
FVG = (PGF, LPD)
RMV = (MDJ, PSS)
TQP = (PVF, KJJ)
SKL = (VFX, CGD)
HDD = (TLG, QGP)
SBK = (NSR, QQK)
GJX = (NPL, STK)
PBX = (HXN, PSC)
KCJ = (CNR, NQM)
FJP = (MXJ, SJV)
NCR = (DNJ, BSR)
NFQ = (RKJ, DMR)
KSR = (PND, RGL)
LCH = (THX, THX)
DQX = (LHH, BHD)
NHT = (JRN, BCB)
SDT = (HXM, NGF)
CHK = (RTM, NDC)
LTM = (VSD, PXL)
KCT = (JBS, JSH)
CBF = (JVM, BNM)
GPS = (NCR, MHD)
VHZ = (MTP, CXB)
BBF = (NQM, CNR)
HMK = (MSM, SVS)
PHS = (TRL, TTT)
SNP = (FTN, KRS)
BHK = (NDG, RBN)
KJP = (VCR, XHR)
NLR = (DLM, MSH)
SXX = (GKT, KNX)
FLR = (GXF, XLR)
HCQ = (JJG, MSF)
JGM = (QDQ, QDQ)
TDF = (QHD, XXR)
BSR = (QCF, SXG)
HLR = (CSS, RVT)
XDM = (GST, XKB)
HHJ = (KJP, MSL)
NSN = (SBK, SDK)
RPG = (RVD, QNM)
JQS = (CNJ, QKP)
CNJ = (NMT, DNK)
VSD = (TLV, FRX)
XLR = (CRF, PTX)
HSG = (DRK, RTL)
FBR = (QRJ, LXR)
KXV = (JSP, RMB)
GVJ = (XRF, VCB)
VLB = (CNC, MDL)
DNR = (VHL, NQH)
TTT = (XVK, LLV)
LLX = (QMH, QDB)
RLJ = (JRN, BCB)
XBG = (PRV, FQZ)
NQN = (XTK, CDV)
LXJ = (KJK, KXV)
MQN = (BDN, HTX)
MBL = (GKT, KNX)
QRN = (VNB, DLX)
PFG = (VMR, QPP)
CDS = (MSR, SSR)
GKT = (MQN, LQF)
BBX = (HMK, SXH)
BMK = (KFG, NFQ)
HRD = (VHM, LHS)
VQR = (RMM, DBK)
JJC = (DLX, VNB)
HPR = (LJM, FGK)
PLM = (LCB, JFJ)
VHG = (CXT, FGG)
CQG = (MKM, MDV)
HDM = (MKB, XTQ)
CRF = (CVC, HRQ)
LFV = (GSM, KJL)
SCT = (MVS, HTG)
PSC = (TGX, BMM)
KRS = (LMP, LVV)
GNR = (JNG, BBG)
NCP = (JQS, CML)
KCQ = (FCS, RLD)
VGB = (QKC, FBF)
TND = (VCX, RDQ)
QKC = (LKH, PJJ)
QKP = (DNK, NMT)
NFN = (FNQ, TCT)
VPV = (DXG, KMX)
SHQ = (XKX, GKL)
RQS = (PMS, SHQ)
JBS = (SXX, MBL)
JJG = (QMC, VSV)
JQD = (VLC, PFG)
TCT = (JMX, VFQ)
VSV = (GJX, TLP)
MXC = (FSR, RNV)
JSS = (KFB, SHM)
DHP = (RFS, ZZZ)
CRH = (XPC, NLV)
SVN = (BPD, FKJ)
LKR = (FSX, BTD)
JNG = (KKN, QPL)
NGF = (XHM, KXD)
CPQ = (NPQ, PHS)
NVM = (TDF, VRG)
BMX = (CDJ, JRK)
TBH = (SNP, CKJ)
CMP = (TLG, QGP)
PMS = (GKL, XKX)
JGS = (HRD, QQM)
LCV = (GKV, HGP)
MHD = (DNJ, BSR)
DGF = (KCJ, BBF)
BQC = (MVK, BPC)
VGL = (VXK, BXP)
DLS = (JRK, CDJ)
FGG = (SVL, DQN)
NHH = (TLQ, DQP)
DSB = (DPF, CBF)
MSF = (VSV, QMC)
SSN = (CPQ, TGM)
PLA = (VVG, JQM)
RVT = (QLH, BTR)
PSX = (QDQ, MQZ)
SRJ = (FBB, RMK)
LQF = (BDN, HTX)
XPC = (DDK, MCH)
MCD = (MKM, MDV)
DBT = (VGL, LDT)
HFR = (QFT, VPJ)
CFJ = (SKH, LMR)
BGT = (PCH, DPG)
QLA = (CXB, MTP)
FSP = (MDM, BTC)
JJF = (MCF, KXQ)
NSR = (LQB, JDB)
KND = (VDK, FNV)
CKJ = (FTN, KRS)
QLH = (LGT, QPK)
TGP = (DLM, MSH)
HVG = (RPG, BBZ)
SKH = (NTK, KND)
DLC = (PLM, VNF)
HVD = (KKS, DNF)
FQN = (DXK, CSM)
DMR = (JSS, LGG)
LNP = (FCS, RLD)
QPL = (LCV, MGD)
RGL = (TMK, SQX)
RLD = (VTL, GVJ)
NCK = (RJP, MGN)
CDX = (RHG, HDM)
CTF = (BFB, XBS)
VKX = (DKQ, PDC)
FSX = (FRQ, CSX)
BTR = (QPK, LGT)
MGD = (HGP, GKV)
FNQ = (VFQ, JMX)
CGV = (NLJ, SBJ)
JVM = (JJJ, RQS)
QDB = (RMV, TTP)
GGN = (DFT, VMV)
QFT = (THV, SCD)
LFP = (DBK, RMM)
RHV = (PLM, VNF)
GGK = (SDK, SBK)
QRH = (JJF, RVJ)
TQC = (MSF, JJG)
KDK = (JSB, HFR)
VKS = (DQX, XHK)
FJH = (FPL, SCX)
RMK = (FQN, DLR)
STK = (VBH, VPQ)
TNT = (XDM, QMF)
SCG = (THX, RTK)
LGG = (SHM, KFB)
GGF = (MGN, RJP)
DDS = (CGV, XVQ)
DMX = (MSR, MSR)
DTN = (LJM, FGK)
FGL = (JHS, PGS)
CSX = (FBP, TKQ)
NDB = (FGL, MTF)
LKK = (NCR, MHD)
MDQ = (LSJ, NSX)
DLR = (CSM, DXK)
JPQ = (PFF, TGH)
NBR = (HKV, HKV)
PTX = (HRQ, CVC)
PGS = (JKJ, SVT)
XLQ = (BDF, BSF)
GLR = (HXJ, TKL)
NQM = (DTF, CBL)
SVT = (TBX, CTJ)
LGT = (HBD, NKJ)
TLT = (KQK, KGJ)
PMJ = (FKR, SBM)
SMX = (RGG, DDS)
NJF = (PTQ, SJM)
QCF = (LMJ, SBD)
DKV = (KSH, BCP)
RRQ = (XPC, NLV)
BTB = (FGG, CXT)
DTT = (VRX, BCR)
LPD = (QJD, HQG)
LMJ = (SSF, XMV)
BKR = (VRH, VNH)
XCC = (KGX, PNX)
FQZ = (CMP, HDD)
MCH = (NBR, SRM)
NPL = (VBH, VPQ)
LHH = (NCP, VGG)
TBX = (LNP, KCQ)
HXM = (XHM, KXD)
KQK = (SVK, SCT)
BHD = (NCP, VGG)
GCQ = (BBF, KCJ)
JMX = (THC, MHG)
SJJ = (MFC, JPQ)
JKH = (JJC, QRN)
PVF = (GCV, LDD)
MNJ = (VSD, PXL)
XVB = (XQN, NDB)
KKL = (DBT, LCG)
MDT = (PRX, KCT)
TTG = (NDL, NDL)
XRF = (GLR, NVF)
VCX = (QLV, LKR)
MDV = (RMD, JRT)
JSH = (SXX, MBL)
CGD = (TGN, NHS)
FRP = (NVM, KDV)
RTK = (TKM, VHZ)
QLV = (FSX, BTD)
TRL = (XVK, LLV)
BFQ = (RBN, NDG)
MDM = (VLB, LXN)
HCJ = (FLR, MCL)
BVC = (XLG, KJX)
TCS = (RPS, KPG)
PKP = (BCR, VRX)
DGL = (KDK, FDF)
VNF = (LCB, JFJ)
TGX = (SJJ, MHR)
MDL = (TNB, BSB)
RJG = (RQB, LQG)
LCP = (RMK, FBB)
QDQ = (VVG, JQM)
TMK = (SGL, NQV)
BHS = (XHK, DQX)
CMG = (VLC, PFG)
SJB = (JJF, RVJ)
VPJ = (THV, SCD)
RKJ = (LGG, JSS)
BDF = (KLT, NCQ)
PCH = (SNG, BPJ)
CML = (QKP, CNJ)
PND = (TMK, SQX)
GTC = (PTQ, SJM)
BMM = (SJJ, MHR)
CTG = (VCX, RDQ)
QKH = (KJT, PLS)
BBZ = (QNM, RVD)
MXJ = (SGS, TBH)
HML = (DPG, PCH)
KFB = (NKV, TCS)
BPC = (BBC, XKR)
JQG = (VXX, XJV)
VKR = (LQQ, SCC)
VVD = (SVN, HDB)
MGN = (HSR, TBP)
NMT = (FRP, FBS)
LCB = (NLR, TGP)
JQM = (PCB, MDT)
VGJ = (VFX, CGD)
GXF = (CRF, PTX)
LQG = (CKS, CKF)
NXM = (FMQ, KBV)
LDT = (BXP, VXK)
TLV = (FSP, VBQ)
CKV = (NQN, JBC)
NQV = (DBH, XHC)
FBF = (LKH, PJJ)
HSR = (PLR, DXS)
XPQ = (MCD, CQG)
VRX = (TLT, HTB)
CSP = (FSC, DGL)
KBR = (DXG, KMX)
XBS = (CMG, JQD)
KNX = (LQF, MQN)
CXB = (BBX, TVN)
FCS = (VTL, GVJ)
XHC = (XLQ, DRJ)
GDM = (GHK, MXK)
VFX = (TGN, NHS)
LXR = (LKK, GPS)
XKK = (PHJ, NHH)
LFN = (LMR, SKH)
DFT = (TDP, XPQ)
NSX = (LCP, SRJ)
NDL = (PRV, PRV)
MTF = (PGS, JHS)
XTQ = (HCQ, TQC)
SPB = (HMS, NXM)
JKJ = (CTJ, TBX)
MCL = (GXF, XLR)
NTK = (FNV, VDK)
VRG = (QHD, XXR)
KJK = (JSP, RMB)
QPK = (HBD, NKJ)
DNF = (PTH, LXJ)
LPS = (LCG, DBT)
GSB = (SCC, LQQ)
KJJ = (LDD, GCV)
FPG = (THT, HBX)
FTN = (LMP, LMP)
SBJ = (LGX, CBN)
AAA = (FPG, LTD)
NDC = (VGJ, SKL)
VLC = (QPP, VMR)
SHS = (LPD, PGF)
JSB = (VPJ, QFT)
LJM = (JSC, QPM)
NLJ = (CBN, LGX)
JDB = (GSS, GGN)
BXP = (GCG, DRD)
PDC = (XTV, PBX)
XQN = (MTF, FGL)
MHR = (MFC, JPQ)
DXS = (TTG, MFR)
DQS = (BKQ, RJG)
TXS = (XLG, KJX)
PDN = (KSF, DPT)
VMR = (VRQ, KNP)
HVV = (XXB, GQP)
VHL = (HPR, DTN)
QBK = (BFQ, BHK)
XXB = (DMX, CDS)
XHK = (BHD, LHH)
KSH = (GMR, XGX)
DXK = (HKN, DJC)
KXQ = (TDX, QJS)
DXG = (LCH, LCH)
BTC = (LXN, VLB)
TLG = (QHK, FJH)
JRT = (JVK, QGT)
RMM = (CFJ, LFN)
MKM = (JRT, RMD)
SSF = (RGS, CGP)
PGF = (QJD, HQG)
KKR = (MXK, GHK)
FBP = (DSB, LFF)
XKX = (KKR, GDM)
FMQ = (VHG, BTB)
CBL = (LFP, VQR)

View File

@ -19,11 +19,6 @@ fn calculate_game(game: &str) -> u64 {
.lines()
.map(|line| parse_line(line))
.collect::<Vec<(Hand, u64)>>();
for hand in hands.iter() {
println!("{:?} {:?} ", hand.0, hand.0.classify());
}
println!("");
hands.sort_by(|(hand1, bid1), (hand2, bid2)| {
if hand1.cmp(hand2) == Ordering::Equal {
@ -33,10 +28,6 @@ fn calculate_game(game: &str) -> u64 {
}
});
for hand in hands.iter() {
println!("{:?} {:?} ", hand.0, hand.0.classify());
}
hands
.into_iter()
.enumerate()
@ -213,7 +204,7 @@ JJJJJ 1";
#[test]
fn it_calculates_test_data() {
assert_eq!(calculate_game(INPUT), 5906);
assert_eq!(calculate_game(INPUT), 5911);
}
#[test]
@ -357,7 +348,7 @@ JJJJJ 1";
Card::Joker,
Card::Joker,
]),
HandType::HighCard,
HandType::FiveOfAKind,
),
];

169
2023/src/day8.rs Normal file
View File

@ -0,0 +1,169 @@
use nom::{
bytes::complete::{tag, take_while},
character::{
complete::{alpha1, alphanumeric1},
is_alphabetic,
},
IResult, Parser,
};
use std::collections::HashMap;
const INPUT: &str = include_str!("../data/day8.txt");
pub fn day8a() -> String {
format!("{}", solve_steps(INPUT))
}
pub fn day8b() -> String {
format!("{}", parallel_solve_steps(INPUT))
}
fn solve_steps(input: &str) -> u32 {
let (path, map) = parse_data(input);
solve_path(&path, "AAA".to_string(), |s| s == "ZZZ", &map)
}
fn solve_path<F>(path: &str, start: String, end_criteria: F, map: &Map) -> u32
where
F: Fn(&str) -> bool,
{
let mut current = start.clone();
let mut cnt = 0;
while !end_criteria(current.as_ref()) {
for step in path.chars() {
let node = map.get(&current).unwrap();
match step {
'L' => {
current = node.left.clone();
}
'R' => {
current = node.right.clone();
}
_ => unreachable!(),
}
cnt += 1;
}
}
cnt
}
fn parallel_solve_steps(input: &str) -> u32 {
let (path, map) = parse_data(input);
let mut cnt = 0;
let mut starting_addrs = map
.keys()
.filter(|k| k.ends_with('A'))
.cloned()
.collect::<Vec<String>>();
for addr in starting_addrs {
let cnt = solve_path(&path, addr.to_owned(), |s| s.ends_with('Z'), &map);
println!("{}: {}", addr, cnt);
}
0
}
fn is_finished(addrs: &Vec<String>) -> bool {
addrs.iter().all(|addr| addr.ends_with('Z'))
}
type Map = HashMap<String, Node>;
#[derive(Clone, Debug, PartialEq)]
struct Node {
left: String,
right: String,
}
fn parse_data(input: &str) -> (String, Map) {
let mut lines = input.lines();
let path = lines.next().unwrap();
let _ = lines.next();
let map = parse_map(lines.collect::<Vec<&str>>().join("\n").as_ref());
(path.to_owned(), map)
}
fn parse_map(input: &str) -> Map {
input
.lines()
.map(|line| {
let (_, (addr, node)) = parse_line(line).unwrap();
(addr, node)
})
.fold(HashMap::new(), |mut acc, (addr, node)| {
acc.insert(addr, node);
acc
})
}
fn parse_line(input: &str) -> IResult<&str, (String, Node)> {
let (input, addr) = parse_addr(input)?;
let (input, _) = tag(" = (")(input)?;
let (input, left) = parse_addr(input)?;
let (input, _) = tag(", ")(input)?;
let (input, right) = parse_addr(input)?;
Ok((input, (addr, Node { left, right })))
}
fn parse_addr(input: &str) -> IResult<&str, String> {
let (input, s) = alphanumeric1(input)?;
Ok((input, s.to_owned()))
}
#[cfg(test)]
mod test {
use super::*;
const INPUT1: &str = "RL
AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)";
const INPUT2: &str = "LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)";
const INPUT3: &str = "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)";
#[test]
fn solves_steps() {
assert_eq!(solve_steps(INPUT1), 2);
assert_eq!(solve_steps(INPUT2), 6);
}
#[test]
fn solves_in_parallel() {
assert_eq!(parallel_solve_steps(INPUT3), 6);
}
#[test]
fn parses_data() {
let (path, map) = parse_data(INPUT2);
assert_eq!(path, "LLR");
println!("{:?}", map);
assert_eq!(
*map.get("AAA").unwrap(),
Node {
left: "BBB".to_owned(),
right: "BBB".to_owned(),
}
);
}
}

View File

@ -5,6 +5,7 @@ mod day4;
mod day5;
mod day6;
mod day7;
mod day8;
fn main() {
let day = std::env::args().skip(1).next();
@ -24,6 +25,8 @@ fn main() {
Some("6b") => day6::day6b(),
Some("7a") => day7::day7a(),
Some("7b") => day7::day7b(),
Some("8a") => day8::day8a(),
Some("8b") => day8::day8b(),
_ => panic!("unrecognized day"),
};