diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1487b4..e8525c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ jobs: rust: uses: lpenz/ghworkflow-rust/.github/workflows/rust.yml@v0.19.0 with: + dependencies_debian: 'libclang-dev libz3-dev' coveralls: true publish_cratesio: false publish_github_release: false @@ -41,6 +42,7 @@ jobs: - day22 - day23 - day24 + - day25 # end if: github.ref == 'refs/heads/main' needs: [ omnilint, rust ] diff --git a/Cargo.lock b/Cargo.lock index 1c16cc7..5908ab9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,6 +437,16 @@ dependencies = [ "z3", ] +[[package]] +name = "day25" +version = "0.1.0" +dependencies = [ + "aoc", + "color-eyre", + "copstr", + "nom", +] + [[package]] name = "either" version = "1.9.0" diff --git a/Cargo.toml b/Cargo.toml index 8b66d84..d793121 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,5 +27,6 @@ members = [ "day22", "day23", "day24", + "day25", ] diff --git a/README.md b/README.md index 6730f44..431ecaa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![AoC](https://img.shields.io/badge/AoC%20%E2%AD%90-48-yellow) +![AoC](https://img.shields.io/badge/AoC%20%E2%AD%90-50-yellow) [![CI](https://github.com/lpenz/adventofcode2023/workflows/CI/badge.svg)](https://github.com/lpenz/adventofcode2023/actions) [![coveralls](https://coveralls.io/repos/github/lpenz/adventofcode2023/badge.svg?branch=main)](https://coveralls.io/github/lpenz/adventofcode2023?branch=main) @@ -16,6 +16,8 @@ Some interesting things that happened on specific days: - Day 20b: had to look at the graph to figure out the "counter result modules". - Day 24b: used [z3] in rust. +- Day 25a: graph min cut problem; did it with multiple Dijsktra, maybe + try [Stoer-Wagner] in the future. @@ -23,3 +25,4 @@ Some interesting things that happened on specific days:
[z3]: https://docs.rs/z3/latest/z3/ +[Stoer-Wagner]: https://scholar.google.com/scholar?cluster=10111487970680388034 diff --git a/day25/Cargo.toml b/day25/Cargo.toml new file mode 100644 index 0000000..9aaeefd --- /dev/null +++ b/day25/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "day25" +version = "0.1.0" +edition = "2021" + +[dependencies] +aoc = { path = "../aoc" } +color-eyre = "0.6.2" +copstr = "0.1.2" +nom = "7.1.3" diff --git a/day25/input.txt b/day25/input.txt new file mode 100644 index 0000000..e5ec3f8 --- /dev/null +++ b/day25/input.txt @@ -0,0 +1,1172 @@ +ckf: rqc +zpm: ffp +lgt: jbp qgn +zcn: jcz srr bbx +vbt: hgx +cgg: qvk +gnb: rtc qtc nvv cmn pjt +rgk: mzv gjk jdk +vxg: hlc fpd kmr lxs vnj +lds: rdt +knb: nrn qhs +zkv: tqg bgb fkd qmp prl mqc +tmj: fbn cjn +jjz: hcg cjk psp +qtc: mdk +kpn: mgj nms +xbp: ksx ckf bxt qbn rjt nrl +dpz: jlq +rgh: tbh +sqf: fqg mvk hsx bhm +bgz: vfk ltk mrl cxr +mjt: hkm vvc spp +jbg: xzp xkr qmg sch xdp +cml: nsm kfq zlk fpn kjq vqd +srk: dtm +dtd: kqx kxm +mkd: ggt nbj tpq +tnq: jfp tzh tcq vnh +ntd: vcq xmd +gcg: ggl xng vkm lst +jsb: rzv +ctr: jxj nvx mjr qlh +dqt: qvk tbl xff pnv xtm +ftr: dkn vkn pcv +zqf: vlz dpv dpp lkm kdt +zdx: jfs +ctx: mpt cqc +bkg: phb mbg cpl kqd +shr: gvv fxh +lzt: xnq +ltv: shp dfr bvb fpn +psp: qrc +shm: trj +nvh: xcb +fjk: hbm gsn bhk +jjv: qgm qml +qps: vds xrj +vqv: hfj +kvk: nrs jkg dhz +vmr: nld btf +mql: dpz kjr fzg +qcg: flr mmq hvx qqd +cpr: vbk sfd pnz qtc hbg +gbh: gmg lxb sbz +gzx: lrg qxp tls dtt +sdr: qgq +tmv: mln ktd qnz hrg +dgz: csz zcs qqp tjn +gxz: rtc +dsh: kfd +cgt: cdh ckf qgx +skj: ffp qgf czj +dcj: zqd nhg zzc +bnt: jtp qmz +zbb: pfv pjc kdk +mdm: zsn hgx lbq qxh +bcj: zpm smt mjq zcs mlq kbq +rcz: qfp +qgx: tvm zjp mkh xxb +svr: zcc btq qbb +pjs: xnd qnq zjn hjn +bmd: gbr lds +lvj: dxs lzm cmk fmg +xkk: lvd dtm +dgd: nmj +vps: tvr rzv tmp pvb +xjh: dmd +tqx: xbb zfm xnq nrt lzt cpq ggm +vcq: kfh fsh +vnz: cqc vzm rjr +zmp: rgh jbp shm +xkl: zgr hbl qkg php +zjp: rkp mqc zxf +pbz: bgv dmd +tnz: xnh shr kbq +lfq: gxj +bhq: zzv rmc mhs vxx +hdd: pzs +lqf: scn brc pkh nms +mck: tmp pks +rtp: pbz vfz kmp +jgh: tkd nmj tnm lzb +bfq: zzh spp hdv +kcx: slg vrk +knc: tjj +bgb: ckj mcq +qpj: qpg jsb tvm +csh: cbf vrn jhh +llc: gbr mzn cpr trt +gsc: xcm krq tdg bkv +fdq: crl thj +cxt: vph +frf: pkc +zrv: kfk sjl tqs grd srl pjg +kvf: rdt +ttc: fmg fmm +qkg: bbd +vxx: jkn xmd sgk +xfh: nch +czc: smj qcz lxb cxq +mcs: gdk knt lcm qmk +mzv: dpz +gkk: gfg vkm +ltk: trj +dcs: rxv jgz +jcz: nmv +fdx: fjm zhz kdp skh qxr +bgx: mbk ksm pdv +lbx: xtd sth tfx +cmn: mkd +rmc: jlq +zvv: cvl ghm +mng: mdc +dhg: bfq dbs fxh hfc +bzz: czm dpz fzg +htq: nlc rnr nrt rkb +lxp: cxm tdz +gqb: tfm jvr kzc +lmt: vgt qdk +kzq: qgf +kps: npl czm bqd dfn +kvv: fsx +crq: qdm pqg qpg +jnr: pkh qmz jkb +bfg: nvq qkg jml dlk rmt +xgr: xrj tzt hfp tsq +lrg: hbg +qmd: cps zgh rfh phb +mtv: cbd +zqn: ljd vpr rsj +tng: cnd vcl gmj xlz +hfk: vzz ppt frc +rll: ppk +vdc: zrr bvm +rts: ffp +hhq: bqs hch qhd +bqm: mbx ckj vmg +jlc: bqb +qjm: vfl cfq +djr: crk xkr +rrn: zxz +vgr: bbx khf +gtg: tpq +jsn: vph +ftt: nnl jcq +mcq: xxb +vfv: zpx zpm +clq: nhg gbl txz +brg: tsf jxs +dqm: kdp qmg +hlq: fpv cjb lzd mfb rcr +hrg: cpl kvn +jbb: gsz svs +pht: dpp +glq: qnq qgm +mvt: kht +mnd: bjv nhg +xnj: hjj dtd mlq qtl qjm +shp: vfk crc hch +txm: zpc rdt vbk gcs ggl +qfm: nsx skj ftt lgf +nvt: dhz bqf ppk +rqp: txl mhl mzq +mvk: mht sbd +klz: njh rzm +btc: jxq +dbv: trj qxc +vsp: kfg tzf +lpf: nkd qhg vlz +knz: qzp gfx +cbd: hrn +pdh: xkk cxl ngm +fgv: xht lhm xdt rtp +bzx: zvc mvt ngj qgd +tls: mbg bhb +ggt: gbl +lgj: tdz chv fcz qqd +zbd: vmr xvt +fqg: jrt qnh +npl: qxp xfj +mqc: ngz mgd trn +zgh: mvq +kmp: dmr +tcq: xxb +xsb: jjq +hkm: phb +fkc: fsh rdt qxp zfg +lqv: cdz lmp vvq +jgz: nmj +hlk: dbl vpl +fft: jhh jhf kfg kxm +pbs: hjj +bvz: rzd mvt xvc sgk +nms: njd +crk: xmd +mjs: fxs zpz bcj +qsr: qzv vfk sxt jxs +tpd: rkk +tfx: mpt pjg +vgx: rfb crk tzf ldc +dlp: sbk tmj +kst: lrf +mkk: fkt +tkd: rvn vcq ldc pdh +rnt: pph +gkz: lrj vnh mqc bvd +flr: kvf dmv cxq +hsl: xmt tdx cjk scm +llr: xbh cxc hpd pjg +qnf: vrn czm kqx +nhn: jxn kqx mfv zpx +rlv: xtd +svs: jnc xdt nrl btb +qxx: xtd +cxc: nsz hjg +hgx: hjv cpp +mdl: gcs pkc zcs +bvc: fqz snv ldm xpz lcm +qlb: txc rzm +cmm: pbq kkf nnt +sgh: fxh snf ngm +qhd: qvk +kfv: vbt krq +sxt: btc bgg +lhm: vqd ztv pzc kvk +tcx: kfh jlq +ghv: jxj rrr mcs zqg +qpx: lzd gqr lxx hmk +bfb: lmg ghm tjf ksf +fxm: dmd cbd kvl bbm +btq: dbs cmk +cpl: dtd +zql: sbd jkb qnh +dlk: cps dgx +frz: zbg dxs nmv gmg +mtn: ckf nxh ltk gfx sxp qmk +rnz: htm lck lzb ldv +rmt: gqk nqn +crl: fqh thj +dnq: sjl zhc gqb pvb +hzj: gqr cgg mrl +dvs: lqr sth vds +bbk: vsm zxz zfc vmd +qdr: xzp skm tlj rts kbt czv +czj: khl kxm +lcc: pgk pks +dgp: lxp gvv +mcb: bnt xng sbz +kjh: jbn lbq qnz rpf +bxt: btb fml vfz +vkg: lmp rjr pmb +hkn: htc +sxk: rck qjk +bcr: hvk vbt hkd +vdr: kfr +cfk: xfh ssb +tvm: jbk +jhh: xlk hhb +dcp: bgv dhz vdc dgs +zqg: qlh xhk kcx pvd +mlq: kqx xbd +mbk: lxp qxp +sfz: tcq fxf bdl xsh mbx +ckq: llp hkm +hbm: tst cdb +szg: bbk bxt vzm bqm fpd +cns: qzp mpt qzv +mxb: lcj lmg jks rvd +pbg: xmd gjx +qmv: cpp fbn +cxp: pgp sht +thj: kdz +qbn: mcq +zsl: fpn trn sjv rcr dgs +djq: kkj xnh xzr jbd +dhz: phq kvt +gfg: xdp +xps: kcp cgg vnj frc mtx +cxr: trj +xdq: czm fsx +kdm: kbq fzl +tvv: mgj rqp jrr klz +vzv: mrl cmq xrc dfg +qkl: dgg vhd vtg bhk fbj +qgd: gkk tdg +dsp: nxz vmp ksm +tsq: xrj mtl sxp +tff: rtc ghh +ndj: khl vsr +ldv: pjj csm stt zhn +bbz: qjf gch rnt zzv +cff: rck rsj +dzg: rnr qnq vxf gjg +tpv: nhg xdp +vjg: rzv nkd ppt gqb pzc +bqd: dpz jdl btf +khz: bjr fft qhs +zbk: nxz qxp +czv: hmm fbl fnk +cjb: cft +vtk: ckj cft bvm fbj +rtd: pcv +zvh: lgx fvh btb +mjz: cdz +bpl: hmh nbj xkr vpd qjr qct +bkh: dpx lvd kst gjn fjv +jrx: jkc jjz +qlc: zcn lmt ntd hxj +xsf: jbn fdq bjv +jbd: ddt +kfq: jpm vvq +qfl: hbl hjq vnk fcn +jxn: sls tpv cbv +fsx: dgd +hsk: prf htc qtb +lgq: mrt +vql: vpl bsc jbk +kpg: tdf fqz rtd +tzt: shq vhd +mqq: gsz +mnr: rpf brc tvd cpl pjj +qdm: dlf +pft: jcq gqk +vhn: lzm gxz lcj jkb bfq zvc +qrf: mcq gfx qzv tpd +shs: dbd sxt +snf: qkm +cqg: mcs qzv mhn qxx +hpc: qmt bqf +mrg: cdl jsg bgb +nrt: hlc hjn +tnk: rll lzt mlt dqf sqb +xsh: rlv +fmg: lrg +gjv: rxv kfh +vlj: rlb kvl bsx +fzg: ddt cbf +gmj: zmh hdr +cpv: zlj +sxp: rck frj +rgb: lbz tdc shq zgc ftr +dgm: qhd +fbn: nvh +hxj: xsf kdz +mkb: bnt kqd ctz qjf sjg +xbj: mjz zgq tsf lml +rjj: nzj ctz zrh +rxh: qbn rjt qzp +tml: xtq frf lst cvl +jjd: bsd gjg cbd +ggj: lxb fbg njd lvd rlg +kfb: rjd mmq nnl lzm +krq: kzq fxh rjj +nxs: ttc ntd pjr hbg tgr +xht: bsx dbd +nsx: ptb vxd sht +xjz: lrf ctl jbn qbv ngm hhb +kfr: hch +phb: gch +lsn: qnh qtl +dfn: nqn +cpp: lds fdj qkm tbg +nhj: hnf hcb lfq +nbj: zvl +nbm: zzg gjv cgj fsv +dlh: tjj kvt qmt +fhr: djr nnh llv +kdk: xdq btq hjj +nvq: kjs tts +gjf: mhr +ftq: svs cjk cjb +jfd: chm mkk zgr zql +ptq: jkn zvc nzj +hpd: msc xbb pht +drf: fkt kjr +grd: fbj zgc lqq +frt: nvt rlv rrn +brs: dmv jnr pdv kqm +psb: mqq hlc jxq qmp +mcn: zpm mht +bdl: lhx jxj spx +bhk: xsh srl +zxz: kzc ldm +bxj: mdg lhp tbh +jnc: zhb jfp +tsn: kpg lzt bgg tnk +qrc: jcm knt tmq +hvk: mdk lrf +srx: qmg rts dxl mdd +mdk: bbd +jfs: lrj +jkz: xlk lgg jkn mzn fpq +sxg: cfq bmd rlg smt +lcj: dbp +gnn: klr zrb +klk: nqr kcq jvc hqq +gqg: fns dpk gjs cmq +kbs: ghh nzj cbf +bsd: lxc zrr +hxv: tmp zqn pfs mtn +pbq: bhp tbg gbl +vck: kjg fhg mvt gbl dbp bxq +pnc: qkm njh +ntm: lfq knq +pgp: mhs hbg xvc ggt +ntk: tpq +bjr: djr npz +qks: jcm pks shq crc +dhl: sbf cjk +kmc: dqm gxz pls fmg +ldc: cgj +ccc: lph qdk clk jrr +qqh: sbf qhg jkg bbb +hjg: kvr mcq ksr +hcn: jfs xtm crc nlc +dpx: pbs czj dbp +qxh: hbn cxq +zbg: lst zmf frf +xzl: krj dmr vvq jbk +qhs: gsm ghh +ncc: jxq +kfn: gnn bzc cgm cbr sdr +djj: tfx rcr xff +plz: mtx msc bxj +zzh: sht +fjv: jhr gxj +jdl: ssg +ljk: hhq qtm cff cpv pzc +jbp: xsh lzd +xpv: jbb mvn +vxl: qjf kfh dgp vvc +jln: zlj +zpn: qrc fpv dmx dgg kvt +hxn: gcn gjf +tnm: jfd kff znj brq +vgg: pdc bqf gjs cjb +kzg: hcg qjd dvk +qnk: gch pnh skm sgk zbd lrk +bfn: dcs mfv ptq chv ltn +vpf: tgr fpq sbz +xmh: fgk sjv dvk mhr +xvv: tpv dpz xlk +jmz: zxz fhx zkg cnd +xnl: fzx pnc pbs +lmc: ncc kvr nvt +lqj: jcm plz +zkg: zhc qgm jxq lqj +dxc: lcb ndj sgh +qlj: chm vtb rtm dvn +sbz: zdd +xnd: dkn +pks: bvm +bvd: qtb +fbj: vpl +qqd: vsr +kvn: mpf rzm +xtq: tvv nnv tpf +qqb: cxt +tbl: glm +pfs: rhs slg +gzm: xff tzq mkh bdl +zfm: hhf +lml: tsr qjk mjz +tqh: gxc zsl vvf +vgt: fkt kht +kxl: hkn zvh rtp knz +snv: vhd +clv: fzx nvv xbd +zhs: rsj kzg pqg skg mck +kfg: zzg +lgf: pfm pnc lrf +fdd: njh zpc lvd +bld: ckq ptb bjr qtt rlg +ksx: vxh vds jvr +vqq: ffl qvr kkj +qlx: bbd sfd llv +bqf: dbd +rjt: qps +lzx: lhv kvl +jqj: gjg kxc ljd njp frj nrs +vzb: lrg txl +cfc: mng vkh lkk lph +zrh: mbg zfr +jlx: mbz cld +gcd: zvl qnf srr jdl jsq +tjf: pmk bmd mln sfd +nvv: zdd +jbn: chv +cqz: clb cxr zhc fxf mrg +tzn: ftr gnn jrx +xmc: dbr scl hvh +fcg: vcl ttn fns +hcg: ldm xdc tbl +bdr: qnz cmm hjv nld +dvn: qlx cfk kvf zcc +hkd: mjq fxb +ggm: hhs vxm nmh +fqz: pvb +zpz: mvq lcj nmv zsn +mkh: pzs lqj +zmj: qsd qtm hnh zxf +qrp: bvm hqq sdh +msj: hxn dmr fkd +qfv: sth kjf vlz +pcd: mbg gjx fzx +mvn: zmh gfx +dkg: qxx tst sdr qvk +pvd: dbv +sqb: mgd qmt +mkv: mjt hmm knb xsf +pmm: vlz dsh pht scq mlt +nvz: lmc dkl tqh mrt +fsv: lmt zvl mnd +nvb: nnh qqb fmg gbr +cpm: rlv mdg lgq +vxm: jln hpc gzs +lcb: php kbs mhl +rjr: hmk dgm +qmr: klz vph xzr xzp +kbn: brc jhf fxs +hhf: xlz +xmt: jjv kfk +rkp: rlv +tqq: tfm hbm +fdj: qqd kfh +tpf: sbk xrq zcc +tjb: mbk xzr zmf +rhs: jkg lxc +ctz: gvv xcb +spx: kfr tcq +xxb: qzv +cdh: zqf dbr vfk +jbs: dcp trj qlh pnv +fzl: zhn rbp txc llv +ttn: dbm +kcl: ckv hpd qzp xbb +mbz: trs +rtz: mht zqd jks +rpd: rkk vnz rnr +vxf: bhk skz +hnz: ksf brd ddc rbl +krj: jnc vpl tdf +gmh: hjv qbs +hmm: ltt ptq +ndp: fml scl jkc fkd +cgh: nnh mcb btf bbd +nhg: ksf +vcx: ttn gbm +qjr: gjz vbk pkc jhf +dpv: hdh +hvh: rgh zdx ncn +xmd: ksf +gzk: vmd cqc fjk dnh xhk +lnp: dkg hbm ljz rth dmr +bpk: mhs jcz dlp +lbn: ddx qjd mvn mbz +jpm: qtb kcq lzd +lln: vzb vkm sgh cps +mbt: btf zvv npz jbd dnr +slk: cxr qxc xjh qhg +bgv: kfr +mxd: kdm xrq glz ntk +fcz: qqd lph +lpc: mck kcx ttn +xpz: gtt kdt mfb +lbz: ngz xhk +vvq: lxx hnh +gbr: jck nch +cjs: mfb bvc ncc xmt +xqk: cpv cpm rll +dcr: mcq bqb gkz bdl +blt: mdl mdc zcn +mgx: ksx cgt ldm bcp +tlm: bhb lrg xcs smj +xcs: mjq mjl crr +mtl: btc +spp: kxm gjh ksm +lzk: zfr bxq cjn lgg +mhb: dfn kbt vqq hzr qxh rzm snf +rxz: fkd tqq pvd dgm +pnh: vfl fkt rtc +vqb: hdh +srh: lpc vxh tjx vhm fns +pfm: tzf srr +lhx: ljd zjn +jjq: knt +cft: zgc +gdt: tbg sdv xvc jhs +kms: nmv qvr nvv htm +gch: rvd +hzr: fnk dxs +jqr: drf dqm bnf tts mql tgr cvc hvk +dbl: gsn +pjt: tzf dxl gjh +dvh: mtx tvr +ldq: bvg tnq bvd jrk +kff: pft nrn xzr sjg +tdx: tnk vkg vxf +tlj: vkm lvd +kkc: hfj jln mdg qgq +cvs: pfs vqd jch vdc +jhs: zcv fcn vgr +rsj: shs +cqc: kvr +khf: ltn mkk qjm +prf: bsc hhf mrl +fpn: gjf scl +rvn: qgf +xxf: mjr shs zrb +bjj: knc xnd mrl gsz +dtm: nrn +ljx: vrk tzt rpj mrb +xrc: kzl mtx +fzx: kjs vsr +sxm: htp tmj qdk mjs +fxg: hgx hjq +tvr: gsz pzs mfb rrn +mxj: xdq hsx kkf qfp dlk +xhk: gtt +zxf: mtv crc +hnf: dgx +hfc: mkk ccz +znj: bjv xnh dnr +cjx: rlr lzk mcb +cgm: hmk dqs prf +vpd: cfq mql vck +zlk: tfx glm jvc +qvc: cxt kdz czm dsp qtl +vfc: hch jrx bbb vmg +sbk: fsh +rfl: gjv sht xnn hvx +xdh: vzb dbp pfm brq +khr: bbb fhx pnv +sjv: qgq +shh: btb djj xrj hlq qgx +scn: pph ntk +zpv: xhz gmj tst hhs tmp +qtl: nrn +lvn: kdp ssg gqz xnl +cbl: kcp rsm +lgx: tmp kfk jxz +hjn: msc +klr: jkc dqs +rvd: ksf +nnt: cvc vxd jrt cmn +lbh: fdj cpp hrg vbt +qgq: gqr +crr: ltt nnl njd +gdk: dsh jvc mkh +pjr: chm mng cpp qvr ffl +csz: qtt zbg zln +dfl: kfv snf kbn vkh +xxs: hfk gsn lxs +qml: lhp gcn +rcm: rls fxg rgr +jrf: chv znj tbm bjr bzq +ngj: gqz +fnr: cgj crl hkm +mph: kfh gjz ntm khl +jsq: kdp gxz +sjj: pbz kgp mfn +fhf: bgv zqf dbv pnf +rkb: dlf +ktd: vpf ngj rgk +mdc: kht fxb +dlj: shm skz bqm pnf +jhg: cmk mcb ggl +pjc: rts mvk ngr +gjk: dcs nmj jsq +xzr: qvr +sjb: kjf rkb +vtx: ztv rlb xjh trs vqd +sls: fxs txc zgr +jfp: rcr rkp +mfv: xbd fbg +rth: kfk qnq kmf +pnf: mtx +zhz: mhs mkd dmv ssb +dgx: ctl +rxv: tbv jrt +vhm: mhr rqc +kxc: vrk frj mgd +tzq: prl rzx kcq +dnr: cgj +tdf: mdg qxc vnj btc +cdb: jcm jbk +dkh: frc bkq ngz +jkf: qsm hpc cft vvf +cts: hjj tjb fjv mzq fdq +qjd: qhd +cch: xtd jrl tdx mrb +xgm: vsp xrq zzh mln kfv npl qtt +gxg: rmt jsq ssb hzr +ltt: zvc cjn +mgj: fsh ksm +kvl: jlc hqq +zfv: vph ngr cxp ntk +fns: vnh vfz +nxj: fpq txl mdk gjz +hfp: kdt slg cld +fnk: btf bhp +txz: rmc cjn dmv qcz fnr +bxq: thj tvd +kbp: lgt qmt vhd dpv +nlc: xjh vvf +qlm: nnl hmz stt mpf jbg +zhb: mck nvt +nnl: dtm +vdm: bkq bsx xpv vhm +zcv: gxj cfq qxr bxq rjd cxt +ppt: pvb +lzv: bsc bsx rpd cdb +zzg: llv +ckj: jxs dnh +dbs: gtg czm +mfn: djc fhx ssn +pkd: dvs bjj jvr jrl +rpf: pfp gfg fxg vgt +rrx: kgj kvv crk zbk +tts: xnn rmc kjp +dqg: qmv skh kzq zbk zfg +hsf: bpk hmz dpj ttc +xdc: rsm +qtt: vrn kvv +bzq: hjq nzj +rzd: vrv qtc +tvk: cxq jcq rgr rjj vck +trt: bgx clq pnc nhn +ztv: dlh +xrj: hrn +jrk: lcc gcn mpp +hmh: rcz +xbb: mkc +dkv: sqb knc qzp vqb +mlt: tjj +fbl: bkv ctl +fhs: dhl qtm dgs +ccz: xcb nld tcx +qmz: qdk +bvg: qtb dpv srl +ddz: cjx fsx blt nhj +skm: fcz nnh flr +hmk: prf +tbm: fbg kpn jhf +vmp: rnt gqk ghm +pdc: mbz rkp zgq +kmq: xzl gdk dvh lmp +smh: rbp ptq zqd npz +tqg: dnh sxk +jhr: gtg +kmr: vkn cld +cbv: qmg fmm vrn +tqk: jck mnd zmf fbl +gmg: lgg +fpd: bvd jsb +kcp: knt rrr +pnz: pgc fcz +glz: cjk lxc +nxm: pgk mtx hnh +mhr: rzv +cps: gjh +qts: jck ngj hkm +kgj: kbn xjz zrh +pdv: tff rjd +jch: klr zkg xnd bsd +rfh: ffp ghh dxl +qzn: dbd vqv nmg +nrs: mkc vzm +dxl: tbv +cld: jxz +ncm: pgk jvc jfs +jvr: xmm xdt +mmv: vvc tpf kst jhr gjx jkn +vbk: qbs lds +plt: dlf gqg snp fhs +gtt: ncc +lqr: zgc +fjm: hvj bqd +hsx: bkv sgk +ljz: lmp dfr mpp +rrp: ngp cxs sxt +jdk: bfq qdk +qqp: tzf sch fhr kvn +zjn: lrj cdz +fxf: tsf fvh pcv lgq +rzx: cns rsm nsz +gkx: rvd lsp sbz rts zbb +rls: jnr kms ndj +mbx: bqb +gfx: dkn svv +xqg: ttq dbm lqv xgr +cxs: dpp +cbb: hsk pfz kzl pmb +hzk: vkh vnk qmz nqn +gsd: ctx bcp qrp kfn +njd: qbs +hpm: kdt gcn gzs sqb lqr rxh pkd +fhg: jsn sgh zbd +cqq: mbg pjc ngm rgr +phs: rbl lsn nxz hvx +nsz: cxs glm +skg: zhc vcx xmt +sdv: vtb xsf hxj +nqn: jsn +rlg: csm +ddx: xdc nsm qff qgn +ztm: rbp kfh jrt ckq zpm +ntn: hfm lzx bfv zgb +bbx: fbg lmg +qbv: brc nrn php +kcq: trs lkm +qmg: fxh ffl +xbh: gzs sjb +gjs: ppk qvk +lcz: lrj mfn dgm fhx +hjv: xlk +zzv: zfx tbv +zqs: gxp hcn dpk cbl dvf mlt kvr +qrg: xhz lgt +kjp: fkt +npq: rhs bsc njp +qff: hkn ksr dmd +hrs: lgq tfm qbn mck lxs +zgb: ksr sjj fhx +qxr: ssg vxd +qjf: ntm +zfc: vlj lzx phq +kjs: hnf ffp +npz: mvq +tjx: qgm hnc zfm +hbl: kjr zzh sgh +vph: nmj +vtg: dkg rkp rck +dgg: cgg fhx +ssn: jjq +ghm: mjl +kgc: vmc dgd xvv mvq fkt +kvt: vnh rlb +hvg: qsd hfj hdd +mjr: dvf dbl jlx +hfm: tqs pcv +vpg: dqs rsm hdh dgs +ptl: qff kxc lsr xmc +nch: gjh +thv: xvt vfl gcs spp +zrr: xtm +djc: kzc kfd +nqr: jxq +knq: fqh +hrn: qsd +xxt: zdd gqz zhn +vpr: srl kjq vqb +kbq: gfg dgd +tjn: kqm hdv nvv +zhc: mtv +xsp: pmb bdn pvd jrk +bhv: bfv rjt crq +jlk: zhb trj dkg +mpp: rrr +tbh: lhp +cpq: bkq rck bqf +kmf: tqg hrn vzz tpd +srr: dnr khl +xhz: pht kfd jlc +ddt: pkh +bnf: lfq +hvj: vfv mjq ddt +qtx: knb lbq xfh dtm +htk: fjp lrj khb psp bhv +njp: ppt tjj +kkf: pls vrv +ffl: llp +xmm: mtl gfx +mmq: lxp hbn lmt +nvx: sdr ttq kzc +lhv: glq djc mgd +xnn: hdv +pzs: qlh +qcz: kjp bfq +jcq: fqh rvn +nrl: bqs shq +dmx: vcl tfm nmd +thh: vqb brg thk pmb fbj dkn +zrb: mpp lqq +dvb: mjz phq lqg qps +lkk: hdv +nmd: qgn qsd lpf +bkm: clb pnv mkc +vkq: zlj zdx zqg hlk +mdd: jgz tpq +dxk: qgf srk kjt skh +kgp: bbb +cdl: bpz mfb kmr +jjh: xrc jbb hvg pmb xgj +pkh: cbf +dkl: hjn jxj dbm kjq +mhs: jck czm +tzh: bkq nqr bgg +lbq: pmk +cbj: rkc nqr bgg spx +khb: zjn cld +pmg: hfc bkv fjm gbl qmz xbd +vcl: cxs +tsv: tlj jhr gqk +smj: kst rtm +fgh: gjv vfl xnh +bcp: nnp gsn fns +tdg: kfg +kbt: gbl knq +fjp: xsb vqv fvh +nzt: kjr lbq jdl cvl +chr: fhf dfg jrl vzz ckv +txl: flr +bpz: trs vzm +jml: xfj zzg stt lkk +lkm: glm ngz +dbx: nvh rcm pjj +vxh: pzc mrb +sjl: tpd bqm jkg hfk qhd knc +bjv: fcn +nnh: zfx gxj gtg +prl: cxc mrb +nlp: kmp gqr jcm lml +gjg: rtd +hnc: rtd dkh +fmm: xng qmv +lqg: qxx bqs clb +dhc: mbz jlk psp +cvc: dxc zgh +bzc: mhn zrr kfq +scm: glz rkc ksr +lpv: jdk fsx csh lck mzq +brd: zcc bcr qqb lst clb +llp: fxb fmn +zxh: hzr zfx rts rvd +nsm: jbk +jxc: dhc sjv gnn xnq mrb +jmj: bsx cff xfr +rqs: nbj tts vgk vkh pjj +zgr: rvn lkk +qck: xxf sjb tsr xqk cmq +lsr: vpl kvr tjx jlx +gcs: khl +snp: dvk dpv bvm +zdn: qfv kzl snv gqg +bxv: rzm nsx cxm gbh +hcb: qxr kfv fmn +lmp: xdt +pfz: qzp clb tmq +svf: hdr sdh dvf sjb +jrl: rnr bqs +zhn: rcz +pjq: rpd ftq xmm +rtm: htp +xtn: zdd qlb zzc xlk rtz +zzc: cxp scn +zcq: kzv tqq xff zkg ksr +fqh: vxd +smt: pls nch +kkq: rll dqf lbz qml +bdn: vnj hqq +clk: hbn +lth: qhs smh clv psl +lck: qkm ccz xfh lzm +zgx: kzc vqv lxs hnc hdd +zfg: ggt jlq +sdh: ltk +xth: bqb dbl jln dsh +fzz: glq jjv qff +bzn: jjv tlg tzn qjd jxj +xgj: mtr xps rrr +vmc: chm gqk +qnz: lqz tgr jgz +dpj: stb drf zdd +nmv: ssb +lgg: zsn vrv +mhn: zsl rsj +vmg: qtb +gbz: hmh pbs csm fbv +jxj: vql xsb +rpm: tpg qdm mcq cnd +bkv: qfp +kjg: hmz vvc qdk +cvl: kjr nmj zpc xvt +pfp: tvd nvh khf +jrr: kfh fsh +vkn: vzz xlz dqf +zcs: sfd ctl +vds: vfz +hqv: qrg fgv zpn jsg kfq +qkx: lzb dgp jhg zgh +hzs: mqq vql pqg lrj +mln: zpx +qmm: bxj sth lqg tbh +nmg: rck fqz tmq +stl: xcm fpq sbk +ddc: qlb sgh kjp +bqg: mqc dhc ssn qrg +cmk: hjq xnn +llv: dmv +xfj: xvc tls +rlr: hkd fgh mzq +pqx: bjj npq nkd tvm +clb: xrc +dpp: lxx +rkk: mtv +hkz: tlm kqd tdg zfr +kdz: lxb fkt +zvl: kqd +brq: sht pft bbz +dtz: nsm pgk lbx nmg msj +sbd: pbg +hvq: tcx tnz dbx nnv hnf fxs +pqk: zbj spx hkn knz qhg +lqq: qsm +rdt: gjz +zmh: tbl slg +xfr: qsm rkk +rnr: vmg +qmt: dbd jxs +ckv: dpk nxh +xcm: pkh zfx fzg +pgc: hjj gjx jtp +shq: tst +gvj: vgk gsm ghh +fmn: bkv ltn sgk +vcg: pjq xsb scq nxm zdx jvr +fxb: ltn +nxz: jtp +jks: ltt qts zgh +qmp: ljd jlc xdc hdd +bhm: kvf vxx gmh +zbj: qdm rlv khb kmp hlk +dfg: jjq +qnq: pvb ckj +scq: vdr pqg mrt +htc: pzs +sbf: hdr bpz +tlg: jxz svv lhm plt zmp +dfr: zfm tqs jmj +qpp: zbd hjv mhb cpl hvx dsp dlp +mjl: tbg vsp +ptb: fcz htm +vgk: htm +dtt: cxm xkk +sch: jck clk +kjt: xng hrg vmc pls +pcp: skz qvk vcx vdc snv +hhs: zrb shq +bhp: nnh tff +nnp: glz nmh qpj cpv +txd: npl ggl qnh +frc: mdg +xhh: fgk ctx jbk frt jsg +pjg: xtm +thk: tbh qgn xxs +tvq: zgc njp vsm lhp +lrk: pcd xxt bbd stb +ppk: msc +tft: gzk jsg kzl jcm +mtr: mfb gbm sxk +scl: shs zxf +grx: njh rbp zsn zql frf +mhl: qlb vph llv ghh +nxh: rlb knc +tdc: jcm rsm cnd +qct: xnn jbd zpx hmz +pnd: vgk qgd jsn xkr mcn dcj +psl: gsm txd mzv +kzv: sth rkb fzz +hdr: qjk +rfb: zpc xvt nvq +djn: jdl mzv tkd bnf svr tdz ftt mcn +tzf: skh +rbl: dgx hbn +mzq: gmg +qhj: htc hfj vdr fcg svv dqs frj lhx +hfj: jjq +vrq: pnc sjg gtg gqz +vvf: xbb cmq qjk +jnt: rrp qsm pjq vrk +sdd: gkk bnf dtt qkg +kxr: tvd clk gmh bzz jcz +bbm: glq zgx cbd jsb +vtb: cmk vfv +rql: mrt hnh rrr mtl +vmj: cbl hdh lqr ncm nkd +kqm: kkj fkt +gxp: hxn hfk tpd +gxc: ztv jfp lcc +zlj: xlz pnf +cxl: fqg ldc fcz +brz: kdm jck dfn cmn +fbv: sbd lrg zvv pdv pnz shr +mzn: nld ngr +gvv: kht +jkc: ncn +hjx: rcz bxq fft +vmd: qzp qpg +pph: mdd djr +fml: bdn tmq +vkm: xzp vkh +lqz: rtm lrf stl +qmk: pfz cbj sdh +vdt: zdx qpg sxt kgp +rkc: gbm tsf +dvk: shm +rqc: mkc dqf +gvz: kkj tsv bzq tjb cdt +gjn: vxx xrq vgr +trn: lqq ttn +zgq: xnq ncn +sjg: rjd +ttq: hlc ncn +cdt: lsn mdm vsr +vsm: hfp dhl hfm +ngp: dkh mtl dcp +mpf: tdz cxm +gnx: rhs hzj qxc ttq +jxd: vdr lxc bbz xht +fgk: sbf kfq +dxs: srk pkc +pmk: cgj stt +lsp: fdd ssg rmt +zln: txc kzq php knq +zqd: qlb jkb csm pjj +tsr: qnq qsd +pfv: cfk fbn gtg kvv +bfv: xpv zrb +zxm: mbx rll gzs dpk +qjk: dlf +qtm: brg +stb: tbv mng fcn +lzb: gvj nms kpn +rgr: lph hjx +bhb: xdp rnt +nmh: zmh kgp fvh +lcm: fpv ssn dgm kjq +dvf: kfd gtt +cnc: gbm dfg cdz xbh zmh hhf +vnk: gbr rzd kdk +zfr: gsm +rpj: jjd tnq skz +tpg: tqs svv vkg trj xfr +hhb: qfp qbs +xhx: vrv jtp bxv rbp +nnv: hmh phb rfh fbn +mht: btf +fps: mqq jxz pht tjx +bvb: kbp qzn bxt +qbb: khz lmg vmr qqb srk pkh +htp: pbg qxh +dbm: pvb +phd: bkm dvh hxn qck +fpv: dpk +zmf: zfg +kjf: pmb gjf +cbr: rgh hmk zhb +kjq: dnh +qgh: qfl ngr xcb lfq +fnp: vfk khr phq lxx +dbr: rrn mpt diff --git a/day25/src/bin/day25a.rs b/day25/src/bin/day25a.rs new file mode 100644 index 0000000..c802a13 --- /dev/null +++ b/day25/src/bin/day25a.rs @@ -0,0 +1,122 @@ +// Copyright (C) 2023 Leandro Lisboa Penz +// This file is subject to the terms and conditions defined in +// file 'LICENSE', which is part of this source code package. + +use day25::*; + +use std::collections::hash_map::Entry; +use std::collections::HashMap; +use std::collections::HashSet; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +struct Edge(Node, Node); + +impl Edge { + pub fn new(node1: Node, node2: Node) -> Edge { + if node1 < node2 { + Edge(node1, node2) + } else { + Edge(node2, node1) + } + } + pub fn other(&self, node: &Node) -> Node { + if node == &self.0 { + self.1 + } else if node == &self.1 { + self.0 + } else { + panic!("node is not part of edge") + } + } +} + +type Graph = HashMap>; + +fn group_size(graph: &Graph, start: Node) -> usize { + let mut visited = HashSet::::new(); + let mut frontier = vec![start]; + while let Some(node) = frontier.pop() { + if visited.contains(&node) { + continue; + } + for e in graph[&node].iter() { + let other = e.other(&node); + if !visited.contains(&other) { + frontier.push(other); + } + } + visited.insert(node); + } + visited.len() +} + +fn min_dists(graph: &Graph, ecount: &mut HashMap, start: &Node) { + let mut visited = HashSet::::new(); + let mut came_from = HashMap::::new(); + let mut frontier = vec![*start]; + while let Some(node) = frontier.pop() { + if visited.contains(&node) { + continue; + } + let edges: &HashSet = graph.get(&node).unwrap(); + for edge in edges { + let other = edge.other(&node); + if visited.contains(&other) { + continue; + } + let entry = came_from.entry(other); + if let Entry::Vacant(e) = entry { + e.insert(node); + frontier.push(other); + } + } + visited.insert(node); + } + for end in graph.keys() { + let mut node = *end; + while &node != start { + let edge = Edge::new(node, came_from[&node]); + let e = ecount.entry(edge).or_default(); + *e += 1; + node = edge.other(&node); + } + } +} + +fn process(bufin: impl BufRead) -> Result { + let input = parser::parse(bufin)?; + let graph0 = input.into_iter().collect::>(); + let mut graph = HashMap::>::new(); + for (node, connected) in graph0.into_iter() { + for other in connected { + let edge = Edge::new(node, other); + let e = graph.entry(node).or_default(); + e.insert(edge); + let e = graph.entry(other).or_default(); + e.insert(edge); + } + } + for _ in 0..3 { + let mut ecount = HashMap::::new(); + let nodes = graph.keys().collect::>(); + for node in &nodes { + min_dists(&graph, &mut ecount, node); + } + let ecut = ecount.iter().map(|(e, v)| (v, e)).max().unwrap().1; + let Edge(n1, n2) = *ecut; + graph.get_mut(&n1).unwrap().remove(ecut); + graph.get_mut(&n2).unwrap().remove(ecut); + } + let g = group_size(&graph, *graph.keys().next().unwrap()); + Ok(g * (graph.len() - g)) +} + +#[test] +fn test() -> Result<()> { + assert_eq!(process(EXAMPLE.as_bytes())?, 54); + Ok(()) +} + +fn main() -> Result<()> { + do_main(|| process(stdin().lock())) +} diff --git a/day25/src/lib.rs b/day25/src/lib.rs new file mode 100644 index 0000000..3458f61 --- /dev/null +++ b/day25/src/lib.rs @@ -0,0 +1,52 @@ +// Copyright (C) 2023 Leandro Lisboa Penz +// This file is subject to the terms and conditions defined in +// file 'LICENSE', which is part of this source code package. + +pub use aoc::*; + +pub const EXAMPLE: &str = "jqt: rhn xhk nvd +rsh: frs pzl lsr +xhk: hfx +cmg: qnr nvd lhk bvb +rhn: xhk bvb hfx +bvb: xhk hfx +pzl: lsr hfx nvd +qnr: nvd +ntq: jqt hfx bvb xhk +nvd: lhk +lsr: lhk +rzs: qnr cmg lsr rsh +frs: qnr lhk lsr +"; + +pub type Node = copstr::Str<3>; + +pub mod parser { + use aoc::parser::*; + + use super::*; + + fn name(input: &str) -> IResult<&str, Node> { + let (input, name_str) = character::alpha1(input)?; + Ok((input, name_str.try_into().unwrap())) + } + + fn line(input: &str) -> IResult<&str, (Node, Vec)> { + let (input, node_name) = name(input)?; + let (input, _) = tag(": ")(input)?; + let (input, node_children) = multi::separated_list1(tag(" "), name)(input)?; + let (input, _) = character::newline(input)?; + Ok((input, (node_name, node_children))) + } + + pub fn parse(mut bufin: impl BufRead) -> Result)>> { + aoc::parse_with!(multi::many1(line), bufin) + } +} + +#[test] +fn test() -> Result<()> { + let input = parser::parse(EXAMPLE.as_bytes())?; + assert_eq!(input.len(), 13); + Ok(()) +}