From 9b5111f033f908a694592a724190c736005cd0f3 Mon Sep 17 00:00:00 2001 From: Alexandre Jesus Date: Wed, 24 Jan 2024 16:16:12 +0000 Subject: day19 --- data/19/example.txt | 17 ++ data/19/input.txt | 797 ++++++++++++++++++++++++++++++++++++++++++++++++++++ day19.lisp | 144 ++++++++++ 3 files changed, 958 insertions(+) create mode 100644 data/19/example.txt create mode 100644 data/19/input.txt create mode 100644 day19.lisp diff --git a/data/19/example.txt b/data/19/example.txt new file mode 100644 index 0000000..e5b5d64 --- /dev/null +++ b/data/19/example.txt @@ -0,0 +1,17 @@ +px{a<2006:qkq,m>2090:A,rfg} +pv{a>1716:R,A} +lnx{m>1548:A,A} +rfg{s<537:gd,x>2440:R,A} +qs{s>3448:A,lnx} +qkq{x<1416:A,crn} +crn{x>2662:A,R} +in{s<1351:px,qqz} +qqz{s>2770:qs,m<1801:hdj,R} +gd{a>3333:R,R} +hdj{m>838:A,pv} + +{x=787,m=2655,a=1222,s=2876} +{x=1679,m=44,a=2067,s=496} +{x=2036,m=264,a=79,s=2244} +{x=2461,m=1339,a=466,s=291} +{x=2127,m=1623,a=2188,s=1013} diff --git a/data/19/input.txt b/data/19/input.txt new file mode 100644 index 0000000..452f67a --- /dev/null +++ b/data/19/input.txt @@ -0,0 +1,797 @@ +brk{s<3727:A,m>3500:A,s<3845:A,A} +lt{a<982:A,s<274:vg,R} +cms{s>621:A,x<502:dz,m<3295:R,nzd} +mfd{a<2692:A,R} +xcv{x>3826:R,a<1965:A,A} +gtr{m<2488:R,s>1479:R,x<766:R,R} +cm{m<2381:ff,m<3360:A,a<210:R,dd} +fks{m>3641:llh,x>3409:xr,s>2575:xh,kvx} +qpk{x<1633:A,x>1755:R,A} +qtr{a>671:A,A} +fdj{s<2953:mpr,gx} +sdh{x>3471:pq,bqm} +kkq{m<3791:R,a<1960:R,m>3871:xck,A} +fxf{a>2645:R,a<2563:R,s>1762:A,A} +mzh{a<3350:R,R} +xd{m<3532:R,A} +rcr{s>340:A,x>158:A,R} +xmj{m<2852:mqq,pxh} +ccj{s<3489:R,m>1373:fl,R} +dm{x>2462:R,m<3451:A,A} +tvg{m<407:A,A} +sl{s<3430:A,A} +csm{m<2603:kz,m>3229:pdr,x<2006:pn,kt} +vp{m<1377:R,R} +fz{s<3314:A,R} +cl{s>2425:bm,A} +mt{x>3089:fks,s<2167:nhd,ck} +hdj{a>2641:rld,m>501:jcg,x<790:kpb,hzs} +fr{s>1476:A,m<2837:A,s<840:R,cn} +prt{x>1207:fqk,x<1076:R,R} +mhd{x<215:A,a<614:A,x<473:A,A} +qg{s<819:chx,tz} +xzs{a>3775:R,a<3614:tkl,x<440:dxb,zff} +xjx{m<2030:A,a<1186:R,s<3638:R,R} +srj{x<1029:slm,a<390:rf,s>2991:dl,cl} +tm{m<2243:bn,jfc} +pc{m<3591:zjn,m<3847:A,a>2274:R,hvg} +crq{x>2138:R,A} +fl{m>1681:A,R} +mxd{a>2884:pkc,s>2033:hnt,vpk} +gr{a>3121:R,R} +bpv{s>1041:A,s>841:R,R} +kft{a>2883:rhq,a<2461:ns,xmj} +qch{s>1420:R,A} +qq{s<3024:A,a<1621:R,x<3397:R,A} +hf{m<1930:bf,dp} +lb{s>3448:A,R} +zmv{s<3274:R,x>3417:R,A} +ctr{m<3609:R,a<1962:R,x<2540:A,A} +hkp{s>1646:A,srp} +mvx{m>2859:R,x<3488:A,R} +vhb{a<363:qch,A} +bp{s>2455:R,dsv} +hsh{s<530:hxt,s<1090:xrl,jtv} +bx{s<2039:A,a<3303:R,m>2291:R,R} +pnd{a<2844:rgz,m<2449:A,m>2479:jn,gqk} +qlk{s>2611:A,s<2092:A,A} +vqb{a>443:A,A} +jnk{s<2464:bbp,fz} +qf{s>2452:A,x<3493:R,a>2585:R,A} +hhf{s>3215:A,s>3204:R,R} +fqk{s>3289:A,A} +ts{s<637:vqb,a>588:sb,rl} +fqr{x>2070:R,s<2020:R,m<253:kk,R} +xhf{s>2527:tqf,a<1637:jpp,s>1510:stv,A} +vv{x<236:A,A} +phz{x>1705:A,bcs} +rpq{a>371:A,a<189:A,s<1681:A,A} +ksd{x<861:gnl,m<1879:bd,x<1267:R,A} +llh{s<2375:R,m>3826:R,a>3360:dhv,zmv} +dl{x<1110:gn,R} +kc{s<2887:bcz,x<730:qlq,gjq} +rnv{a>2030:R,A} +jfz{m<3510:A,x<232:tbr,R} +vz{m>3640:A,x>486:R,R} +rh{x>2717:lp,dsz} +vb{m>3771:R,x<1919:A,R} +pfr{s<3524:krf,x<1618:R,R} +rsd{a<2380:R,m<3388:jp,fn} +gx{s>3460:cf,a>961:xt,m<2457:rqx,hg} +qpz{x<571:A,m<900:R,a>1295:R,R} +ctj{a<2109:rcr,R} +cg{a<801:nrl,m<655:ljs,xq} +tvv{a>3123:dx,m<3516:A,lql} +pbn{m<2844:A,m<2979:R,x<869:czg,R} +psc{x<2808:fls,fd} +mfn{s>361:gbb,mmx} +rq{m>3477:A,bdt} +qjf{m>3469:jf,a>3075:R,s<3247:zfg,R} +pt{a<943:A,s<2493:R,A} +nqk{x>1088:A,m<3482:cjv,R} +nm{x<3016:A,R} +lrn{m>2221:R,s<944:R,R} +nx{x<1228:R,A} +dd{x<3424:R,x>3749:R,R} +kvn{m<3865:A,s>2276:A,s<1944:A,A} +fdd{s>1070:A,s<510:R,A} +db{s>3186:dpk,a>267:gzv,a<165:nqj,cm} +hzl{x<3742:tds,A} +ng{m<3172:xbl,m>3206:nfn,A} +tx{s>3352:A,x<761:nvq,qqb} +qk{x>1230:sv,s<2839:cc,s>3467:kqx,nqk} +fdg{x>2748:A,A} +hdp{m>194:fc,hn} +kfn{s>1076:sqq,x<3311:R,A} +kqx{a>2382:qrf,x<1127:A,A} +xcj{m<1971:A,R} +xbh{a>2219:A,A} +zff{m>3648:A,R} +gb{m>3833:A,R} +fm{s>3311:sdh,s>2946:db,vx} +hvm{x>852:A,A} +vvl{a>3121:R,x<1888:A,R} +mqq{x>649:A,a<2667:djs,s<2270:nrh,R} +lvr{x>3164:A,A} +mm{m>1622:R,m<1576:R,a<3617:R,A} +dnl{m<1785:pdh,x>1500:qh,m>3058:gk,fmj} +znf{a>3644:R,m>616:R,R} +jx{s<2270:dc,mhd} +qkm{m<3068:A,m>3082:A,s<2345:A,A} +vpk{x<476:R,s>906:lqh,s<543:R,A} +np{a<2600:A,A} +sdc{x<3298:A,x>3586:A,R} +gd{a>2233:A,rnr} +pxh{x>956:pbh,x<633:tpx,s>1719:fml,mfd} +ccb{x>1805:zzt,gtc} +fjj{m<3563:R,a<3062:A,R} +bxd{a<2061:dht,x<1214:ddg,s>713:phn,xxm} +gc{a>3697:A,x>1586:R,A} +pq{m<2538:R,brk} +st{s>985:A,R} +sj{s<2968:qtr,s<3559:A,s<3717:xjx,A} +cc{x<1067:xtc,m>3623:R,R} +mf{m<640:A,R} +jh{a>1578:A,a>1429:kd,gsd} +kk{m>146:A,x<1964:A,a<2410:R,R} +tg{s<2462:A,vh} +gv{m>886:R,A} +pfs{x<1627:A,x<1710:R,m>3873:A,R} +cv{s<841:A,m<3680:R,A} +fsl{s>594:cz,m<3496:vt,x<3596:nb,cs} +sk{m<420:R,R} +fd{x>2977:R,x<2893:A,x>2941:A,A} +xtc{m>3658:A,s>1963:A,R} +fv{m>1518:tb,R} +rzz{a>2302:R,a>2054:A,x>2519:ctr,R} +tl{x>1375:mqn,x>1305:qcv,A} +mfj{s>525:A,R} +tpx{a>2714:A,R} +jn{a<3598:R,R} +lh{s<765:fjj,x<2579:R,a>3123:A,A} +vl{m<640:A,A} +nkb{x>1198:csm,s<1799:qg,x>616:tgp,fdj} +qcv{s<2985:A,A} +khd{s>1945:A,x>438:R,x>179:R,R} +hg{a<485:A,R} +cz{m<3595:kv,A} +mp{m>2937:R,s<2500:A,fdq} +kpb{m>238:rv,m>140:R,rjv} +pns{m>1520:kj,s>2684:pfr,jm} +qrh{x>2812:R,R} +rm{x>723:sxc,bb} +vk{m>877:A,x<981:A,a<2928:A,R} +hbn{m<831:tvg,R} +jrl{s>3423:A,R} +rjv{s<2026:R,R} +sgk{a<1410:R,A} +xh{m<3280:A,m<3424:lb,x>3301:A,lvr} +gbb{a<2591:A,m>3659:A,R} +kz{m<1495:dg,s>2364:sj,hh} +lpc{a<1432:xp,x>3244:kr,hp} +jvz{s<3621:R,R} +tkl{m<3638:A,A} +vm{s<1460:R,x<567:R,R} +ph{s<2907:A,a>1552:R,x<3818:R,R} +czg{m<3013:R,x<517:R,m>3043:A,R} +sr{x<3617:R,x<3755:A,x>3887:A,A} +gl{m<3472:R,a<2437:R,x>338:R,R} +dhv{x>3631:A,x>3309:R,m<3743:A,R} +zj{x<2822:R,R} +zc{x<2284:R,R} +tk{m<243:R,a>762:A,A} +fn{s<1386:A,a<2507:A,x>1878:R,R} +pct{a<796:R,R} +gqk{a>3284:R,m>2462:R,m>2455:A,A} +pkc{s<1958:R,s>2881:kh,s<2559:A,R} +fst{s>907:R,s<859:A,A} +dr{m<1214:zkm,x<1089:mxd,s<1851:bcc,pns} +rsx{m>1063:R,s<2954:R,R} +jqc{x>3241:vc,A} +rgz{x>558:R,m>2449:R,m>2406:R,R} +pdh{x>2318:vnv,m>793:dr,a<3139:cq,frf} +ps{x<2979:A,A} +lj{m<1381:R,m>1474:R,R} +pzr{s>2658:R,A} +mg{m<3270:R,s<324:R,s>434:A,R} +qqc{m<3150:sp,x>1498:R,m>3190:A,kg} +srp{s>918:A,m>3662:R,m>3473:R,R} +gpt{s<362:A,m<1712:zq,qc} +xt{x<319:R,s<3141:tv,m>2094:R,R} +css{x>562:A,x>354:R,A} +tpm{a<111:R,R} +gzv{a>336:R,A} +cn{m<2915:A,x<1526:A,s<1244:R,A} +zfg{x>459:R,m<3274:A,A} +bjn{m<513:nnv,xmv} +gz{a<2008:A,x<3451:R,s<2017:A,A} +lph{s<3046:R,A} +bf{m<1858:hb,a>3679:A,A} +kh{x>519:A,A} +bn{x>1011:A,m<1155:nmp,qvd} +jbq{x<483:R,A} +lql{x<1189:R,s<794:A,s<1096:R,A} +sqq{m<344:R,R} +lk{x>1380:R,x>555:A,rj} +bxb{s>964:A,m<2003:mfj,x>560:R,R} +hh{m<2169:R,m>2318:A,lrn} +pk{x>383:R,x>129:A,m<708:R,A} +kls{x<895:R,s<2440:A,a>1576:R,A} +tb{a<1584:A,R} +bbp{m<2468:R,m>2511:R,s>1950:R,A} +stq{s>1124:dhj,x>3727:ts,pm} +jjf{a>2228:R,s<676:R,a>2168:R,R} +dxq{m<1766:A,x<3488:A,x<3716:A,A} +scv{m>1319:A,s>1706:A,R} +cb{a>954:R,s<3281:A,A} +kj{s<2613:R,a>2986:mm,bg} +rhc{s>496:R,s>252:A,A} +kn{s<2246:A,A} +bqm{a<174:ps,x>2831:A,pb} +nv{x<846:nr,zl} +tp{m<3318:R,a>894:R,s<2534:R,R} +srq{s<2858:xg,hzm} +nr{a>3476:xzs,s>2508:qjf,md} +gj{x<2161:R,A} +czm{s>222:A,m>3220:A,R} +mqn{m<3143:A,R} +js{m<2226:dlt,zhz} +qpb{m<126:A,m>255:A,a<2135:R,R} +zzt{x>1994:gj,a>2235:R,s>2411:R,R} +kd{s>3005:A,a>1499:R,A} +lr{a>2103:xcz,kfn} +sxc{x>889:R,s>3111:R,x>824:A,R} +tf{s<2663:A,s>2689:A,m<851:R,A} +qc{a<351:A,x<934:R,R} +gbr{a>705:cb,m<2130:sh,A} +ljs{m>294:A,A} +nb{m<3714:A,s<381:jdr,gb} +rld{x<607:hlt,m<447:R,R} +rk{m>3616:A,s>3146:A,s>2420:A,A} +ddn{a<370:R,R} +hl{x>3111:prr,m>1911:gbr,ccj} +bk{s>3269:bt,x>3219:lph,gm} +bb{m>3596:R,A} +pp{m<3651:bkz,frs} +qv{x>982:qk,znt} +tqf{x>2607:R,x<2521:R,A} +mht{a>2451:A,m>1438:A,m>1341:R,R} +sgs{m>3460:A,m>3201:shc,A} +mfm{a>2176:R,s<614:R,A} +lx{a<1079:A,R} +nqj{s>3042:R,x>3012:R,qrh} +ddd{m>3779:R,A} +kt{x<2175:mp,ckn} +dxb{x>170:A,A} +zfb{a>421:R,s>878:A,R} +dlt{m<2140:np,s<1831:R,xrr} +dx{a>3306:A,m>3568:R,a>3212:A,A} +snv{x>641:R,R} +qvd{m<1570:R,A} +zd{s>2964:A,s>2728:A,R} +ff{a<230:A,R} +sg{s<993:A,m<849:A,A} +nsf{x>3378:stq,a<715:snm,dh} +vt{a>2421:mg,czm} +nvq{m>3480:A,R} +jcg{m>647:A,x>816:R,m>579:jbq,A} +znt{s<2517:vr,x<552:jfz,a<2437:rm,tx} +cjj{s<2391:R,rsx} +dp{s<2929:fk,s<3614:R,m>2016:xmc,A} +hqd{x>3367:R,s>1503:A,R} +hk{s<277:R,s>483:R,m>1358:R,btx} +sgg{m<2348:js,jzh} +nfn{a>2132:R,x>1793:R,A} +ftj{x<1389:R,R} +xcz{m<466:A,a<2325:jjf,R} +kzs{a>1910:A,x<951:R,A} +xxm{m>3336:xcs,a>2151:A,ftj} +mnn{s>3268:A,A} +rl{m>1634:A,A} +crp{s>557:R,R} +fkh{a<1419:pz,rs} +xxb{a<2370:A,A} +mh{m>3820:R,x<2083:A,a>2996:R,A} +fgb{s>2569:A,x>2450:A,R} +nk{a<162:A,m<2726:frn,xpj} +fc{x>1147:rvm,R} +lm{m<3260:ng,rsd} +cf{s>3729:rbt,m<2604:jvz,mq} +dcf{x>3774:R,s<3116:R,R} +lxx{x>1530:sl,x>518:vk,R} +tgp{x<868:kc,a<752:srj,a<1341:tm,dk} +kxv{a>891:R,R} +zq{m<604:A,A} +in{a<1805:pkg,dnl} +zjn{m>3311:A,R} +qqb{s<2931:R,x<851:R,R} +pkg{x>2464:ljb,nkb} +xg{a>149:A,m>2665:R,A} +hc{x>279:cms,s<810:ctj,ttg} +pm{s<517:R,m<1522:zfb,A} +bcc{a>2934:xlj,x<1869:tkh,pnl} +dj{m<103:R,m<138:R,A} +nhd{x<2267:px,a<3424:lh,x>2623:szv,dm} +bz{s>1704:qkp,x<3526:gr,R} +rlz{a<3140:A,a>3293:R,x<297:A,R} +vr{m<3643:R,a<2289:khd,htn} +xr{a>3318:R,s<2341:A,s<3166:fcb,tn} +cnp{m>911:R,m>568:A,tq} +cq{x<1353:hdj,kx} +zf{x<3828:A,a>1730:A,R} +vx{s>2774:srq,m<1675:jt,s<2684:hv,nk} +fnv{x>1143:R,R} +xm{s<2292:R,R} +kkp{m<2571:R,s<2085:hx,m>2800:gvm,R} +hv{s<2661:A,m>2764:A,A} +hzs{a>2161:R,x>1063:A,rnv} +dh{x<3018:xdd,jqc} +kvr{s<2242:vv,pk} +hxt{a>2221:R,A} +fct{m>3536:R,a<2575:A,R} +ndh{m<972:znf,A} +mpr{m>2022:jx,a<771:tg,s<2472:kvr,cnp} +cp{m<2848:mzh,m>2927:gbz,A} +nzd{s>238:R,x>606:R,x>549:R,R} +mmx{x>1313:R,m<3589:R,A} +vbr{a>3008:A,s<584:A,s<808:R,R} +pmh{x>3296:R,m<489:sk,mf} +fjg{a<1047:ddn,m<3101:qkm,a>1301:A,qnd} +msp{m<717:gjj,a<3625:fgb,bxp} +snl{x>3421:A,m<252:A,R} +jdt{a<3134:qcg,s>1586:hf,cxg} +xmc{x<570:A,x<1144:A,m>2053:R,R} +kx{m>382:phz,x>1822:fqr,ztt} +gbz{x<965:A,m<3013:A,m>3029:A,A} +mx{x>3328:hzl,a<3372:jmc,x>2691:ndh,msp} +frn{x<3473:A,a<285:A,R} +bcs{x<1512:A,m>603:R,A} +ttg{a>2011:R,A} +hp{m>1412:psc,x>2760:hbn,xhf} +nz{s>3208:R,s<2786:R,s>2974:A,A} +krf{s<3091:A,m>1327:A,A} +bcz{x>711:pt,a>1188:A,s<2432:A,A} +rnr{a<2207:R,R} +rj{x>314:A,s<912:A,a>3832:A,R} +dg{s>1406:A,zsq} +mzv{x>3263:R,R} +qcg{x<980:lsp,qx} +zhz{a>3088:jzq,kp} +mzf{x>1264:A,R} +btx{m>888:R,x>745:A,R} +jtv{x<1844:mlv,x>2006:R,x>1914:A,htc} +dgl{a<3453:R,s>2663:A,A} +rp{m<2155:qpz,s<1318:sn,s<1583:css,R} +tc{s<2033:A,a>1598:zf,a>1490:ph,dcf} +hr{s<3608:R,x>447:R,R} +rtb{m<2921:A,R} +djs{x<335:A,s<1702:R,m>2691:A,A} +nh{x>2140:R,m>1477:R,x>2039:A,A} +kf{a<2025:R,s<3004:A,A} +xlj{m<1564:lj,m>1698:tj,a>3333:gc,jc} +jfc{a>995:R,x<1009:A,x<1095:A,tp} +tkh{s>682:xxb,s>330:crp,a<2194:rz,mht} +gn{x<1066:A,R} +rhq{s>1782:cp,pbn} +vj{s<3790:A,m<339:R,x<2823:A,A} +tps{x>674:A,s<3265:A,A} +szv{x<2868:ft,x>2976:vkh,s>841:R,rhc} +trj{a<2273:jlj,gs} +skv{a<2338:A,s>2958:R,s<2678:A,R} +xmv{s<2988:A,s<3065:klm,kxv} +hx{m>2810:R,A} +sc{s<2986:A,R} +zqz{s<3128:fg,x>611:jrl,A} +frf{s<1691:jl,m<423:hdp,vrr} +gsd{m>2232:R,s<2763:R,A} +shl{a<2163:rd,x>3349:bp,nd} +kr{x<3615:qmz,tc} +bc{x<3311:A,s<3351:kf,xd} +xgj{s>3591:A,m<548:R,x<3697:R,A} +pnl{a>2241:nh,rcn} +chx{x<575:lt,a<897:gpt,x>917:fkh,hk} +fhs{m>700:R,A} +nrh{x>238:R,a>2784:R,a<2732:A,R} +hrz{x>1950:hm,a<902:A,m>3685:R,R} +pxb{x>1142:mzf,gdx} +xvz{s>561:ccg,R} +xcs{s<422:A,a<2161:R,A} +rx{a<3008:A,m<901:R,A} +tbr{a<2365:R,s>3452:A,s>2930:A,R} +frp{x>900:htl,s>573:sq,kkq} +md{s>1652:vz,s<1077:vbr,rlz} +ms{a>2247:fct,a>1974:A,s>2168:A,zc} +frs{x<3540:kvn,m>3878:A,xcv} +dgd{s>3214:hr,m<644:tnm,x>467:mr,R} +lq{s<3221:sc,m<3569:A,x<3563:lvc,ddd} +nnv{s>2853:tk,s>2735:snl,m>327:A,fln} +qx{a<2498:R,a>2737:A,m<1893:fxf,R} +xrr{s<3174:R,m>2190:A,x>908:A,R} +hvg{a<1985:A,A} +htl{a>2010:R,A} +lsp{s<2234:xcj,m>1926:A,skv} +rd{s<2503:R,x<3017:fdg,A} +jds{x>1157:A,ssh} +ddg{m>3417:mfm,x>942:ml,s<466:hvm,A} +kv{a<2344:A,A} +xdd{m>2260:A,a<992:gv,scv} +jc{a<3114:A,R} +sql{s<3259:br,a>3232:ggp,mh} +snm{m>2141:vhb,m<1213:pv,nhb} +vkh{s<955:R,s<1453:A,A} +vnv{a>2559:mx,m>739:shl,s<1629:lr,cht} +bkz{m<3362:gz,a>1950:hsz,R} +slm{x<964:R,s>3235:vp,x<998:R,A} +ft{m>3486:R,A} +xck{x>451:A,A} +hsz{a>2033:A,a<2000:A,m<3504:A,A} +vh{a>503:R,s<2712:R,s>2843:A,R} +pn{m<3019:fr,s<1453:qqc,x<1554:tl,fjg} +px{x<1919:A,a>3411:crq,R} +qkp{a<2827:A,m<2764:A,A} +hn{a<3478:R,dj} +gk{a>2753:nv,s>1384:qv,qtk} +ggp{x>2183:R,A} +tz{a>850:rp,nxm} +jzh{x<856:pnd,s<1629:xvz,jnk} +rvm{x<1863:R,m<286:A,A} +kcm{x<915:kls,qlk} +xp{s>2278:zk,hq} +fls{a<1668:R,A} +kg{a<833:R,s<541:R,A} +td{s<1606:fsl,s>2769:qs,a<2163:pp,dqq} +cxg{m<1949:ksd,a>3471:bxb,a<3282:ch,snv} +jkx{s<1504:A,kn} +rn{a<535:R,A} +qh{m<3052:rh,a>2744:mt,x>2911:td,pj} +nrl{x>3482:xgj,s>3672:vj,a<577:A,vl} +cht{m>330:pmh,bfr} +vg{x>366:A,R} +fcb{s>2877:R,a<2979:A,m<3367:A,A} +rv{s>2225:A,a<2143:R,A} +fdq{x>2118:A,A} +dz{a<2077:A,m>3350:A,s>221:R,R} +cs{m>3766:szs,x<3765:A,R} +jlj{x>2392:A,x>2372:A,R} +qrf{m>3565:R,s<3757:R,R} +pb{a>351:R,a>257:A,A} +qnd{a>1151:R,x<1745:R,x>1864:R,A} +ck{m>3671:sql,sgs} +mq{a<1025:A,s>3611:R,s<3520:R,R} +htn{x>503:A,m>3852:R,s>2112:R,A} +pz{a<1213:R,s<531:A,A} +shc{a<3329:R,s>2874:A,s<2537:A,R} +gnl{a<3649:A,R} +dqq{a<2368:gd,s<2264:rq,bcq} +qr{s>3033:R,s>2249:R,s>1972:R,R} +kp{a<2531:R,s<1615:R,a>2828:R,R} +xpj{s>2734:A,m<3285:R,x<3369:A,R} +sbs{x>2566:pc,x>2455:rzz,x>2351:trj,ms} +sv{a>2152:R,a>1957:R,s<2504:A,ktn} +ch{x<818:R,s<530:A,A} +dc{m>2856:A,x>364:R,a>679:A,R} +ccg{a>2984:A,a<2383:A,R} +kzq{a>2303:A,xbh} +tds{m<1004:R,s<1678:R,x<3470:R,R} +stv{x<2625:R,s>1999:R,m>887:A,R} +tn{m>3378:R,a>3123:A,A} +xrl{x>1894:cv,a>2121:A,x<1674:mn,A} +rql{x<292:A,A} +bm{s<2693:R,a>530:A,A} +jf{s<3466:A,m>3716:A,R} +rz{s<154:R,A} +nt{m>1697:R,R} +sft{s>3185:A,x>1604:dgl,x>1373:xm,pzr} +lvc{s>3545:R,s>3369:A,A} +rf{a<197:tpm,s>2658:A,s<2248:R,A} +tnm{m>562:R,x<697:R,x>882:R,A} +nd{a>2411:zj,x>2779:nm,R} +jzz{x>717:xf,x>282:A,m>3530:st,bpv} +hm{m<3674:A,s>3421:R,a<946:A,A} +dht{a>1916:R,a>1856:R,m>3310:fnv,A} +lv{a>1547:R,nt} +jzq{m>2270:R,A} +pbh{a>2740:A,R} +rqx{m>877:A,m<466:rql,fhs} +jm{m<1319:R,m>1434:A,vvl} +bd{x<1278:R,R} +phn{s>1047:R,x>1340:R,A} +htc{s<1275:R,a<2126:R,m>3702:A,R} +bs{m<2785:vm,kzs} +tv{s<3016:R,m>1424:R,A} +mn{m<3801:A,R} +ndr{a<2451:A,R} +gjq{s<3377:mqf,R} +xdq{x<1040:R,R} +tq{m>255:A,x<241:R,m<126:R,A} +ktn{m<3428:R,R} +sn{a>1291:R,R} +lqh{s>1302:A,A} +bdt{x<3511:R,R} +bfr{a>2244:A,x<3334:A,a>1974:qpb,qr} +fp{m>3697:R,a>2058:R,x>1621:R,R} +xq{m>820:mzv,m<714:A,sdc} +jl{a<3597:xdq,lk} +dsz{a<2722:kkp,bx} +nhb{a>443:R,m<1590:xjt,A} +qtc{m<857:A,A} +pv{m>556:qtc,rpq} +lp{m>2290:bz,lgs} +ml{s>883:A,a<2164:A,s<393:A,A} +fg{x<893:A,R} +kvx{x<3291:A,x>3337:hqd,x>3313:fdd,mql} +mqf{s>3110:R,x<798:R,A} +kmt{s<1459:R,m>3633:vb,A} +bcq{s<2597:qf,A} +fk{m<2037:A,R} +hnt{a<2261:R,x<687:A,x<935:A,R} +pj{x>2249:sbs,m<3497:lm,s>1474:ccb,hsh} +cjv{a>2375:R,a>2069:A,R} +bg{x<1849:A,a>2393:R,a<2075:R,R} +pdr{s>2635:hrz,a>617:kmt,x>1754:jkx,hkp} +fmj{m>2534:kft,m>2093:sgg,jdt} +tj{x<1824:A,m<1745:R,x>2008:A,R} +hlt{a>2845:R,a>2760:A,x>221:A,A} +ljb{a>1200:lpc,s<2627:nsf,a<441:fm,gfb} +sh{s<3242:A,s<3602:R,R} +zl{s>2245:prt,s>1272:pxb,a>3502:jds,tvv} +nxm{s>1200:gtr,s<965:fst,R} +nzs{m<882:sg,m>905:nx,x<886:R,R} +ssh{x>965:R,a<3788:A,A} +mql{x>3299:A,a>3451:A,A} +vrr{x<1239:dgd,sft} +gxq{m<3686:ndr,m>3886:A,x<829:A,R} +xf{s<1136:R,A} +jp{m<3305:R,R} +bt{x>3254:sr,s<3547:R,s<3826:A,R} +qtk{a>2269:rjn,m>3609:frp,x>707:bxd,hc} +fml{x>777:A,R} +lgs{a>3182:A,x>3362:R,m>2105:A,A} +szs{m>3858:R,a<2142:A,R} +gjj{x<2561:A,a>3790:A,R} +mlv{s>1239:A,m<3825:A,x<1728:A,A} +zsq{a<619:R,x<1745:A,x<2145:A,A} +qmz{m<2523:R,s<1599:R,qq} +zk{x<3150:R,zd} +rs{a>1601:A,R} +qs{a>2415:lq,bc} +gdx{s<1774:R,A} +jpp{m<764:R,m<1091:A,R} +jt{x>3303:R,x<2817:ttm,s<2710:tf,A} +klm{s>3017:A,m>799:A,m<681:R,R} +ztt{m>192:R,a>2369:R,qpk} +fln{x<3047:R,m>193:A,a<853:R,R} +br{x<2460:A,R} +hq{m<1545:A,s>849:rtb,mvx} +rbt{m<2269:A,x>339:R,a<1074:R,R} +ns{s>2422:zqz,a>2120:kzq,bs} +dk{x>1017:jh,x>954:lv,s>3140:fv,kcm} +sb{s>897:R,s<753:R,R} +jdr{s>209:R,m<3863:R,m<3923:R,A} +rjn{s>679:jzz,x<530:gl,x>1059:mfn,gxq} +gfb{m>2467:bk,m>990:hl,s>3218:cg,bjn} +ttm{s<2678:R,A} +gvm{a>2405:A,s<2926:A,m<2950:A,A} +gtc{a<2342:fp,m<3796:rk,pfs} +hb{m<1813:R,A} +zkm{m>940:cjj,s<2335:nzs,lxx} +sp{s<869:R,m>3063:R,a<1081:R,R} +gs{s<1767:A,A} +rcn{x>2139:R,R} +dpk{a>173:R,s>3240:mnn,hhf} +vc{a<1019:R,R} +prr{a>765:R,dxq} +qlq{s>3515:R,a>727:A,tps} +hzm{m>1445:R,R} +sq{m>3864:A,m<3760:R,x<438:R,A} +xjt{x<2801:R,a>256:R,R} +bxp{x>2497:R,R} +mr{m>730:R,R} +gm{s<2923:pct,m<3485:R,x>2891:R,A} +dsv{s>1297:A,m<1434:R,m>1572:R,A} +xbl{a<2315:A,a<2548:A,s>2455:R,A} +jmc{s<2500:rx,a<2842:R,x<2783:A,nz} +ckn{a<715:A,s>1703:sgk,lx} +dhj{s>1705:A,rn} +nmp{x<937:A,x<974:R,a>973:A,A} + +{x=97,m=3034,a=520,s=1230} +{x=48,m=2597,a=1043,s=2427} +{x=520,m=825,a=547,s=205} +{x=90,m=1232,a=115,s=882} +{x=1532,m=1668,a=2430,s=2369} +{x=2095,m=753,a=347,s=1636} +{x=15,m=3389,a=126,s=2070} +{x=793,m=1658,a=310,s=2364} +{x=959,m=1660,a=1185,s=681} +{x=1109,m=1979,a=109,s=336} +{x=415,m=424,a=1721,s=270} +{x=323,m=1374,a=905,s=1917} +{x=1450,m=1674,a=3109,s=2981} +{x=205,m=89,a=1825,s=443} +{x=92,m=70,a=712,s=655} +{x=209,m=1050,a=320,s=1643} +{x=488,m=834,a=1222,s=520} +{x=32,m=746,a=577,s=133} +{x=1206,m=740,a=223,s=1454} +{x=109,m=978,a=3025,s=222} +{x=149,m=1568,a=186,s=367} +{x=49,m=680,a=375,s=113} +{x=1071,m=321,a=194,s=866} +{x=1099,m=246,a=767,s=3686} +{x=463,m=1245,a=132,s=180} +{x=2031,m=2121,a=127,s=99} +{x=22,m=384,a=2498,s=1219} +{x=1647,m=1199,a=1182,s=450} +{x=1383,m=1078,a=240,s=1829} +{x=481,m=995,a=475,s=428} +{x=1461,m=1352,a=186,s=246} +{x=871,m=1677,a=41,s=2389} +{x=26,m=3600,a=1,s=2609} +{x=229,m=498,a=633,s=325} +{x=1893,m=314,a=678,s=505} +{x=3819,m=1,a=101,s=734} +{x=1247,m=520,a=564,s=390} +{x=134,m=1176,a=275,s=1027} +{x=873,m=2365,a=667,s=659} +{x=271,m=189,a=332,s=826} +{x=1928,m=972,a=191,s=2033} +{x=403,m=379,a=3351,s=833} +{x=629,m=690,a=486,s=1} +{x=360,m=3135,a=352,s=583} +{x=1066,m=889,a=949,s=402} +{x=1953,m=229,a=1595,s=179} +{x=861,m=2271,a=700,s=20} +{x=9,m=1627,a=81,s=2023} +{x=313,m=1388,a=667,s=1091} +{x=1137,m=1665,a=124,s=626} +{x=1061,m=429,a=54,s=1830} +{x=815,m=51,a=550,s=1247} +{x=124,m=952,a=897,s=1886} +{x=680,m=148,a=2408,s=2} +{x=3132,m=1257,a=1604,s=1052} +{x=698,m=749,a=81,s=59} +{x=2834,m=262,a=1239,s=2597} +{x=191,m=218,a=444,s=53} +{x=1740,m=750,a=46,s=335} +{x=468,m=531,a=2898,s=1772} +{x=655,m=1360,a=2860,s=973} +{x=854,m=529,a=1226,s=550} +{x=486,m=785,a=2418,s=614} +{x=534,m=1710,a=2052,s=594} +{x=116,m=2580,a=27,s=428} +{x=778,m=1090,a=1359,s=1328} +{x=405,m=2739,a=3242,s=2159} +{x=34,m=2314,a=1055,s=857} +{x=1110,m=1263,a=216,s=2526} +{x=1177,m=284,a=1042,s=1597} +{x=251,m=3649,a=1844,s=1427} +{x=872,m=1048,a=1991,s=411} +{x=2299,m=154,a=113,s=2699} +{x=399,m=432,a=939,s=7} +{x=2885,m=756,a=344,s=96} +{x=1945,m=2586,a=1677,s=787} +{x=1497,m=1101,a=1879,s=349} +{x=1066,m=938,a=1124,s=27} +{x=285,m=370,a=2779,s=1235} +{x=210,m=203,a=1392,s=2350} +{x=3118,m=2349,a=342,s=108} +{x=1181,m=668,a=1853,s=2686} +{x=143,m=662,a=404,s=37} +{x=3342,m=2811,a=432,s=630} +{x=539,m=432,a=160,s=465} +{x=378,m=752,a=1528,s=32} +{x=579,m=903,a=1012,s=807} +{x=5,m=606,a=2425,s=2214} +{x=409,m=493,a=1110,s=3168} +{x=1662,m=1930,a=20,s=1684} +{x=49,m=2284,a=528,s=29} +{x=106,m=1201,a=1842,s=572} +{x=2,m=1241,a=489,s=2092} +{x=747,m=774,a=1023,s=51} +{x=766,m=2744,a=1260,s=35} +{x=225,m=85,a=313,s=203} +{x=1065,m=3852,a=3001,s=224} +{x=1080,m=68,a=2236,s=579} +{x=1202,m=709,a=650,s=113} +{x=1368,m=50,a=1621,s=72} +{x=142,m=761,a=557,s=154} +{x=1898,m=77,a=380,s=707} +{x=1022,m=155,a=3318,s=556} +{x=376,m=1130,a=1293,s=7} +{x=268,m=873,a=408,s=453} +{x=2057,m=1316,a=1370,s=1291} +{x=81,m=285,a=1445,s=2015} +{x=2449,m=725,a=1567,s=1198} +{x=2550,m=779,a=178,s=9} +{x=719,m=574,a=3040,s=2694} +{x=272,m=92,a=1526,s=811} +{x=10,m=354,a=285,s=476} +{x=43,m=2071,a=1017,s=501} +{x=680,m=1749,a=2515,s=3395} +{x=369,m=1441,a=444,s=820} +{x=1946,m=616,a=398,s=1840} +{x=693,m=3478,a=53,s=487} +{x=2902,m=429,a=237,s=525} +{x=442,m=209,a=2734,s=1911} +{x=3447,m=953,a=696,s=392} +{x=658,m=65,a=1036,s=821} +{x=720,m=570,a=40,s=463} +{x=1607,m=147,a=952,s=1673} +{x=1169,m=1312,a=481,s=2083} +{x=709,m=160,a=186,s=1370} +{x=1283,m=2187,a=337,s=89} +{x=2933,m=2469,a=55,s=1198} +{x=1009,m=813,a=1280,s=1980} +{x=1128,m=446,a=56,s=2315} +{x=320,m=839,a=1176,s=1555} +{x=2719,m=1776,a=2869,s=593} +{x=1236,m=2786,a=1644,s=131} +{x=1806,m=1125,a=196,s=2414} +{x=175,m=1618,a=381,s=2136} +{x=748,m=58,a=1006,s=676} +{x=449,m=56,a=852,s=428} +{x=1447,m=515,a=2256,s=550} +{x=2372,m=2045,a=845,s=2483} +{x=3147,m=1641,a=708,s=702} +{x=123,m=426,a=4,s=59} +{x=615,m=253,a=1880,s=1551} +{x=99,m=1119,a=473,s=987} +{x=3070,m=1697,a=1137,s=2525} +{x=967,m=2275,a=429,s=106} +{x=1615,m=2679,a=405,s=166} +{x=1564,m=200,a=307,s=154} +{x=74,m=2971,a=1556,s=199} +{x=3023,m=1890,a=2602,s=416} +{x=2854,m=67,a=662,s=718} +{x=95,m=97,a=214,s=252} +{x=2025,m=788,a=191,s=880} +{x=975,m=485,a=355,s=52} +{x=619,m=758,a=491,s=569} +{x=197,m=12,a=193,s=2070} +{x=839,m=652,a=20,s=24} +{x=83,m=92,a=309,s=536} +{x=3025,m=501,a=1418,s=1540} +{x=42,m=1817,a=170,s=2125} +{x=808,m=662,a=41,s=577} +{x=30,m=142,a=1692,s=474} +{x=854,m=1999,a=3126,s=1189} +{x=346,m=1370,a=1116,s=2035} +{x=233,m=752,a=516,s=1179} +{x=3217,m=3109,a=29,s=73} +{x=484,m=2314,a=225,s=2} +{x=898,m=2681,a=2313,s=1328} +{x=1095,m=1220,a=331,s=1174} +{x=3569,m=1665,a=27,s=324} +{x=170,m=2228,a=3119,s=618} +{x=17,m=186,a=1137,s=5} +{x=75,m=938,a=235,s=73} +{x=569,m=330,a=1178,s=1201} +{x=2288,m=199,a=2644,s=21} +{x=741,m=580,a=114,s=1896} +{x=234,m=524,a=1372,s=616} +{x=1027,m=27,a=905,s=1145} +{x=170,m=24,a=888,s=1257} +{x=2412,m=2908,a=327,s=627} +{x=2041,m=1036,a=1798,s=3228} +{x=887,m=164,a=75,s=2456} +{x=56,m=595,a=1643,s=86} +{x=88,m=394,a=292,s=277} +{x=1343,m=1241,a=2035,s=180} +{x=50,m=150,a=496,s=378} +{x=1414,m=828,a=1585,s=226} +{x=3243,m=117,a=1357,s=141} +{x=528,m=854,a=259,s=619} +{x=40,m=794,a=1497,s=2787} +{x=2157,m=388,a=658,s=993} +{x=911,m=1159,a=346,s=1165} +{x=105,m=916,a=84,s=2514} +{x=2577,m=1880,a=601,s=2679} +{x=2262,m=1108,a=1022,s=45} +{x=780,m=445,a=291,s=201} +{x=3173,m=535,a=1280,s=3422} +{x=1308,m=49,a=910,s=1391} +{x=944,m=158,a=3,s=1409} +{x=125,m=340,a=1970,s=3505} +{x=145,m=2289,a=1040,s=1482} +{x=1395,m=1185,a=224,s=1174} diff --git a/day19.lisp b/day19.lisp new file mode 100644 index 0000000..8011426 --- /dev/null +++ b/day19.lisp @@ -0,0 +1,144 @@ +(defstruct problem workflows parts) + +(defstruct part x m a s) + +(defstruct rule var op value res) + +(defun read-rule (string) + (if (not (position #\: string)) + (make-rule :res (subseq string 0 (1- (length string)))) + (multiple-value-bind (value ind) (parse-integer string :start 2 :junk-allowed t) + (make-rule :var (aref string 0) + :op (aref string 1) + :value value + :res (subseq string (1+ ind)))))) + +(defun split-by-char (char string &key (start 0)) + (loop for i = start then (1+ j) + as j = (position char string :start i) + collect (subseq string i j) + while j)) + +(defun read-workflow (string) + (let* ((aux (position #\{ string)) + (name (subseq string 0 aux)) + (rules (mapcar #'read-rule (split-by-char #\, string :start (1+ aux))))) + (cons name rules))) + +(defun read-workflows (stream) + (let ((ht (make-hash-table :test #'equalp))) + (loop for line = (read-line stream nil) + while (> (length line) 0) + do (let ((workflow (read-workflow line))) + (setf (gethash (car workflow) ht) (cdr workflow)))) + ht)) + +(defun read-part (string) + (let* ((x 0) (m 0) (a 0) (s 0)) + (loop for i = 0 then (1+ j) + as j = (position #\= string :start i) + while j + do (let ((num (parse-integer string :start (1+ j) :junk-allowed t)) + (chr (aref string (1- j)))) + (cond ((equal chr #\x) (setf x num)) + ((equal chr #\m) (setf m num)) + ((equal chr #\a) (setf a num)) + ((equal chr #\s) (setf s num))))) + (make-part :x x :m m :a a :s s))) + +(defun read-parts (stream) + (loop for line = (read-line stream nil) + while line + collect (read-part line))) + +(defun read-problem (filespec) + (with-open-file (stream filespec) + (make-problem :workflows (read-workflows stream) :parts (read-parts stream)))) + +(defun part-accepted-p (part workflows) + (labels ((f (rules) + (loop for rule in rules + as rvar = (rule-var rule) + as rop = (rule-op rule) + as rvalue = (rule-value rule) + as rres = (rule-res rule) + if (let ((pvalue (cond ((equal rvar #\x) (part-x part)) + ((equal rvar #\m) (part-m part)) + ((equal rvar #\a) (part-a part)) + ((equal rvar #\s) (part-s part))))) + (or (not rvar) + (and (equal rop #\<) (< pvalue rvalue)) + (and (equal rop #\>) (> pvalue rvalue)))) + return (cond ((equalp rres "A") t) + ((equalp rres "R") nil) + (t (f (gethash rres workflows))))))) + (f (gethash "in" workflows)))) + +(defun solve1 (filespec) + (let ((problem (read-problem filespec))) + (loop for p in (problem-parts problem) + if (part-accepted-p p (problem-workflows problem)) + sum (+ (part-x p) (part-m p) (part-a p) (part-s p))))) + +(defun range-size (range) + (assert (<= (car range) (cdr range))) + (1+ (- (cdr range) (car range)))) + +(defun subrange (value op range) + (if + (equal op #\<) + (when (< (car range) value) + (cons (car range) (min (cdr range) (1- value)))) + (when (> (cdr range) value) + (cons (max (car range) (1+ value)) (cdr range))))) + +(defun inv-subrange (value op range) + (if + (equal op #\<) + (subrange (1- value) #\> range) + (subrange (1+ value) #\< range))) + +(defun range-combinations (workflows rulename x m a s) + (cond ((equalp rulename "A") + (* (range-size x) (range-size m) (range-size a) (range-size s))) + ((equalp rulename "R") 0) + (t (let ((rules (gethash rulename workflows))) + (loop for rule in rules + as rvar = (rule-var rule) + as rop = (rule-op rule) + as rvalue = (rule-value rule) + as rres = (rule-res rule) + as range = (cond + ((equal rvar #\x) x) + ((equal rvar #\m) m) + ((equal rvar #\a) a) + ((equal rvar #\s) s)) + as sub = (when rvalue (subrange rvalue rop range)) + if sub + sum (range-combinations + workflows + rres + (if (equal rvar #\x) sub x) + (if (equal rvar #\m) sub m) + (if (equal rvar #\a) sub a) + (if (equal rvar #\s) sub s)) + if (not rvar) + sum (range-combinations workflows rres x m a s) + ;; update subrange + do (cond + ((equal rvar #\x) (setf x (inv-subrange rvalue rop range))) + ((equal rvar #\m) (setf m (inv-subrange rvalue rop range))) + ((equal rvar #\a) (setf a (inv-subrange rvalue rop range))) + ((equal rvar #\s) (setf s (inv-subrange rvalue rop range))))))))) + +(defun solve2 (filespec) + (let* ((problem (read-problem filespec)) + (workflows (problem-workflows problem))) + (range-combinations workflows "in" '(1 . 4000) '(1 . 4000) '(1 . 4000) '(1 . 4000)))) + +(print (solve1 "data/19/example.txt")) ;; 19114 +(print (solve1 "data/19/input.txt")) ;; 495298 +(print (solve2 "data/19/example.txt")) ;; 167409079868000 +(print (solve2 "data/19/input.txt")) ;; 132186256794011 + + -- cgit v1.2.3