advent2023

Advent of Code 2023 solutions
git clone git://bsandro.tech/advent2023
Log | Files | Refs | LICENSE

commit 808cdc3ce6e41aa17cd4e11864b1014a84151097
parent 400f9eff0c93a10b16411abee556cecf358638f3
Author: bsandro <email@bsandro.tech>
Date:   Fri,  1 Dec 2023 09:39:05 +0200

day 01 p1

Diffstat:
A.gitignore | 1+
Aday01/Makefile | 25+++++++++++++++++++++++++
Aday01/input.txt | 1000+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday01/main.c | 30++++++++++++++++++++++++++++++
Aday01/puzzle.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Aday01/test.txt | 4++++
6 files changed, 1105 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/day01/Makefile b/day01/Makefile @@ -0,0 +1,25 @@ +NAME=$(shell basename ${PWD}) +SRC=$(wildcard *.c) +DEPS:=$(wildcard *.h) +OBJ:=$(SRC:.c=.o) +CFLAGS=-O0 -g -std=c11 -Werror -Wall -Wextra -I. -I../common +LDFLAGS=-lc + +all: $(NAME) + +.PHONY: clean run + +clean: + rm -f $(OBJ) $(NAME) + +%.o : %.c $(DEPS) + @$(CC) $(CFLAGS) -c $< -o $@ + +$(NAME): $(OBJ) + @$(CC) $(OBJ) -o $@ $(LDFLAGS) + +run: $(NAME) + @./$(NAME) input.txt + +test: $(NAME) + @./$(NAME) test.txt diff --git a/day01/input.txt b/day01/input.txt @@ -0,0 +1,1000 @@ +7jlncfksix7rjgrpglmn9 +vcgkgxninerqjltdbhqzzpd4nine23 +fx3 +8nrbjbpjpnineseven +7qlfhcsnxn7fpfhjcgr6eightsevenjlpchjtzpztwo +28rzgskgk94ninefive +zdpxcql1eight5 +8two5six37 +9khfphjl71trppsrtwo +lxthkgbbf2jdcssfiveqksvbqvm8four4 +seven9tjcgztctxzzttct +onetljcfh9fivesvgcqnklz9four +4mptgcnzmvvsevenzmjjzhndzdvxmz59bm +1hrqthmr +7eightqmfmsn +jkgdnpzjkzzceighttklsfiveqxgsvxdq4 +hdk28lqhhttjz6one2 +2five524 +363mtk +qlmtpch9eightlzddxs7one +one6five1hxphtl687rllvb +31gdnsxtpnn +sqvbcqlnjhk135 +eightgcdszrsghmmfsevendr2844 +eightthreecdpccfj7 +ljfgt9kvnine175kpnrbttktktf +zjfeightfive9nine44seven4 +sixshbrtr4nmjr +3two54 +26sixbhmmgdcl +drxfnbsdzf3gnxbtmmggvkxrsevenbbzdfxnrdnkfivefive +two8591mrvchg4 +3jjhfzlnklpvvfcnsjbdmgvlfkeight2snxrkzzsx +ztwo79onesix56seven +threeeightrhlxptmtwofivenfourthree3 +fbhcqcttgxlrstcqeight4dbfjp +prsevenfournineglccpgssix7 +hzprzdvbsxzllgvttworstxtwodstxbtjnzm6 +99sevenfive +fdvnvc2 +vmpnpqg32llcxpbzcxqvseven +dc9fgvrvsqqhlj2nq97three +four77twothreeonenine9 +3kfkfour +xfg58six8cjtvmrgvsq5l +gmfxvhftld2hbmmprpppzchcqmxninethreethree3mmplrvbtkf +3fourqndl6 +rj6ninenzkbktfqsc2 +9konehdmllc +mneightzzqvdm14 +8oneseventlrsrzflccrbv +9vvvgqdkrckjlzcfsbdgrqrhhtbb7fnhcxzmk9nine7 +825ngddfhpfrsl6 +mc6tjxxll9seven +fxbgccqmmh2 +five7three4vmxjlqcnc3 +9mninehkmlpcxqnfkqfbg6six3 +3onefourrv1ninesixfour8 +fourtwosdtz817fivevjvlzr +seventhvxk1fournqqqfjrvdvbpkvd +v733rklzvnslkonefive6zbvq +178ncllbfkkh4eightwoq +glbxfjhskzbseven6mjzlxccfive3 +fptwoneonefivefive2ztxpndjdq2 +lxzhsgqkx5mjxtrmbkdtfeightsrchzmq6 +1nngc2338ninedjkvszdmnjrl +five6six7 +bcpxbcbssbtmdfninefivesevendtm9eighthxtvxb +mzdttqmfpssevensixeight3twoone4 +rrtzlhkgrgtmrvlcthreeonefour5 +75threeeight4 +3ttcjsdrj6one91t +3twofgdpfqxxp +seven3gjslxpltpbonemt +82jcvqkrgzkx8three8rmszgdj4 +ctwone41fnjksbxb1mxxzznsvg35fivesix +four7bzfeight3one +heightwo24cxs +fdtwone8sevenfour37 +1sevenmdmlrgmqnnth1mrone +7nqxzdrblffcdm22six +5ttpzlv +zhqjlfive3 +jvzpgppblkb6 +nine77lmfour +kqnvgtkgphxcxsixfoursix2 +pjjdlnineltbcknfqvhj8tworbkqhdcp +nine65fiveeightjmeight +j1sptkfhsczt +4czpqqglpc41bzkss1 +qd28j +three1fourfourm +four5seven4twodvmzzdtn +zj4 +dzzrdkjjdxspfrjsonefive8brrzlrjvzfour +zrjzfxxddn66 +fourrnsphsdzmv9xznt6seven +56eightcbhkmjfourone +fivejzlbvqzb3sixsix +fiveghfclksgqffdpb7 +cmmplbcnml36threetrxnhrrdonelmspsbhfd9twonenn +ccxrlmzrreightone9three9 +zg6four1eight +1ngv +bfhptfjzlgkxtftwo7gthree +txrpbzgjzg272three9jlstdb8 +3seven6twofxvxdlcqj33 +six3eightjrdxgkrkm5five +one67one3 +gnfhhkffqfctxmvznmftwo34gjsrpxlv43 +five6zjdjpptnthreefour7sevenqfjlpshg +onesevenninesvnnrvxxeightrdbvsbdnzgtmlmf1 +2six8seven +3eightjrpqdrtwoxjvmgzpbffjnfdps9 +tptlcldftc3 +lcpqlbjfgmhkjpkhc4eight9ninesixsixseven +eightxjfqqtxnsbsnrdxdjv8six79 +tvkthbbrr8five +seven35threerrkdqjgps58two +5dln1rqqgdjlcmmrvm2pmhvhcxhfsbxkfqngp5 +sixnpvbq36514one +mxdvxfgdfzmkjcrtl2 +onejv7lxmbrbzjsthreesevenninesm +threehbhnm8nine +bvhgqz6 +9two89sixfxjz37 +8xninepvggctk85fivefkj +8sixdjndzzzrkk +five61oneightr +cmthreesixeight7jlvdvmdjfzbv3 +9two1onefour1clxjonetwo +9sixtzphqltmeightlbrhjone1ktrvjldff6 +five68eightfourqpfcxftzlxrhgdcvpd +nxvdtfkltwozzl72fourhzxtqjf1 +91fiveeightthree65twoneh +3eight6ninexqqgxzxfgmsixseveneightfqk +dlpsfmsthree2zgfpdnftvfqgsgr +4kggfpxg8jpxzdqsixeight +fivefourtwo923 +z3gx +six4prlsp84tgvc +1foursrznv62k +vmzr829nkxtlf +3dzsx2two7sixfivebkktgfbzdt +fourpzpmvxc2zvvrhrbhf +frpddtknqjxpqqzhdnfour9sixdqjbqxh +89sevengkbeight6mn +two7jcpnxhbtmhtwo39twoone +cvdqlfkrs821fourrrgnmm +6onefhnnbrzgx7fourxcj +seveneighthfr6rz +9vvqlpnzbxfct8 +two8three2fpseveneight +2three75three2 +znvbrbrqlfive8 +lnfjqfkk8 +14tvvmdlntrv6three +5twor2chtvj +threetwomgrcfivefive7 +five4qbvxthrfxdkjkk +sixthreethree5scmqrfq4vf3 +rjsljnqcrttbpfhfxbfourone4 +threeseventwoseven87dnmqjbbxfoneighttfz +seven4four9eightxqlsixthreeone +1ninesix43bmsttggvzn14 +seven1sixbmnxmz +grqhlkrcdzbhstgtvpclvtphph4twoseven +fgfprscb27pzfvvblxhkvonefive +five77fivethreefive3vddgfngng +13nllfsevenfour6four +threenineeightfour173three +fourqvsbxxzmfh2hhcjxsrkz +4jdtxgltkkkvlnhrztwofxppsdlcqztwo3gdlctj +5four334rvfour9 +551threenine +eightonenineeight8 +qmjqmjvvfkdbnjgkrqh8two +sevenjzqnv32lldmr5one +6five8fivefour +ljvhqqvqxqsix1367 +two6kvjtwonenzf +2p5chjdcseven9 +lnrrrkkdsvfhkl9vfqfgnvonegtwo6 +twoseven4lhhpcvthree4tkrone +8hllnnmpm3rjxndcmpt9jfjqng +qbnlgqeight2csvjshglqzmgkqqxqzq95 +two2nine +rrpffkq15foureighttwo2 +five3ninetpx5fmrzsqvfzq +mrqhcpgvblhvskv5pdsdzzfzfsix +two7fvmhvseventwo7 +3sixone94three8fdplbm2 +loneightseveng79 +fourone7 +zvgjt1 +xpgbfghsmj2six8eight8mzlnvmv7 +grjtwo48 +jhcgjlgxt1seven1 +5dhtppxrxcsbjsm37 +cbhmtp56xbqzppjjfivezhtxxvkrzsix +hctwonelcninefourfive2 +four4rcxpkzbeight95xxdb3 +fivejlplgzflone963two +trgninefourtwo6five +66fournine535foursxbvsfvf +1bskfour +dvlmbrxssevenhldvjxdzcfdvbfourthree2seven6 +6two92635 +8dzszone +hfcm6 +dxrfhpdbrqmqq8four +bfclp5sixeight81three +eightffsqgkmt53gfjxqsskpsfpbcmqvdfour9 +6sevensevenfour1v +9threetfspsfxhnzblgsxz +seven5tz7pfhlpt9qxrqz +pmbeightwooneonefiveseventft4 +xhjhmzljnx7 +twotgdvhkpmg1rthzfc6 +onesevennpcsbfive9sixseven +7sevenmbhlrjxrpddcnl +8fsvntpptctwobjmkgzvc4two +onetwosix4 +fourthree4fourlqbvscdponeights +1glkfrdb69sixsrvvb +ninetwoeight7cvjtdmgpsfivefnlvgsqtstwo9 +9threejtfoureightseven +38nine8 +87two7onetwo +2vkkcgxdqpnthreehklfmfmjdpkz9fivetwofour +one5oneone5oneone +three5hlxkxrmxsbgrzqsgrone +twokbbnbjp7 +mvxpdllxrvfthreeone51eight +rrqvfiveseven5two1qgqppn +92s +fourxcj8frbvlxzgpvoneone +648211 +4eightgzxnsixlvksllptszztmkjb3four +fivegqg6 +foureightmmnknlseven1 +83kx +sixeight12kskzhrjjpslmprtwo +1xzncrsfrlfivetwoxptv46nine +fourmxfq6twotwo4 +oneht8 +3prjdlrcznine +btkpqmxxmggkzftmkxbzqvdccchxdmjlqztzfgfour7 +tvbstznine9z +two1fivemmnlcnmqlrnbp95gjjh +dq671ninezk +6cmxtt769 +629rkhc198 +2fourfiver +three5nqkjdsixfrjnf4gcbjrznine +xjhqqf7oneeightrgkdprrssmxp63 +5fourfivekpvmnlpfrt1 +xnqkjcldhttbpjr8 +fdntjsb957sevenhbmntp +jlmmmmdv482three +63lnbhmdhpsp32 +99cmntldfdflqkfkv +kqnlqqkpr9eighteightthree15threenine +6threefttghrvjsjg6 +spmrjzfm6eightwokn +bdcjfqvsdronertfztlblqbgfgtkjv8qhbjfhthree6nine +9fvltpsxtcbtjxbtlfdvm7 +6jxvxrdmpjthreefstfgrsixfourzbfznjjlqtjx +8onesixkmhgvsnfhqnxlkn +rrjxvqjbnvvsgddtvmb3six5 +eight8sevenbmtgbvdzcpqnzqone1hbhlgcfour +2nineseven41 +8xptgrh1njz +geightwo93sevenseventwobpdhhjsrbfour57 +m4kd9four +6nine5seven9v +glzc1fiveeightvbmvk +ninesixone3sevenzmvrqbtwo4four +9onefoureightfivefour +fjqpgnjdd1twoninecgsqsmtonenine1f +94sixthreedflcddxnvvrthree +vvfnbgpkgsnjtszxhrsixfive5rrdtfpkdhdvsg +39four1pjfkt +45sixkhlfc1fivetcvnlstnine +sevenone2seven +twofiveonenine6eight5 +grxzndnqpd56 +xnpdfnfgt5fivetwotwo +9four6two +sgmlzbpnkrmfivesbdzbnhkcxndpone49 +88six2hrmkl2 +mthree3eightfiveone +smrzqc7twothree2three +nmtwo8cr +378one47four +27four +5two7seven68six +9onecnonethree9 +nineqhvbjqbrkpjhjhdbpk3twoseven +rq4qldc +86bqzct2nine +eightsnfgrjzhsnxbfivethree6ljxx +oneeight1threevzdcplnqrbk92 +8k9dkqmqhndthreethree +9sp6j5two +4rsone1seven2seventwo +ninehhdcbxfgs7fljclncb6vpzhqphxz +drplsnsch3zfr +86nine +2threeeightsixvzpcqjs +dmkhbxsggeight7seven9 +fourshjlmrbbcnznstgj2sx +gcbzbldk6nine +fourskpc1vzfxsrjckcmccljtt9 +1oneone53oneeight6 +six3fourqxqbs9nkbsixthreesix +pmlrkrhqdjgg121nineseven9 +dmgnq6 +kpmponeone5 +mxmhbqnrcjj1threeeightxzfive +onebzxnrqqfltfourglvkqfive4nine5 +threezvmfl7vsdrthsdsjsix9mbrqqmz1 +boneight8onelrtjkj +tqxbbceight9rqbthreek +3h32nklscdkfhtztwontprj +2threesix +qkzmpvkvsixxfzlrfrgv682 +3seven6mvkeight2fourvhvvqone +three389sixeight +bx664nine +nine82rcdvqtj91dbffscng4 +2sixsixtbqhvcndjtcvrrbtdzsxrlrvdxjtd7fzdtlrhlxvbpvhknmm +6zbpblsznhlzljtmstwothree28ngdcfkk +eight8nbfmdqlcvonenine +8two4sx7rffstvxlq1seven4 +gmzbd8nine5nine1one +sevenfivezdfbn7six +5892 +ss9 +8xcvzgzkjcdg +1seven7three +8four1fourtwonezs +hnjzk8 +xfour5mrj +vnkspgtkxspdtwofxlvtlkqpqcffxbqth13cll +mmjkshtmtwofour1 +sixthree6 +seven9mzmbkkrzsix5five +9cbrsqjlhntpzfivegmgn1six +bdbnlrdpsninenine3twotwocpvjd3 +twonine193 +twothree1twor8cmtxtd +bvgtninevfrjs6 +eightsix8 +sixfbzsxfjtfv8 +5onethreeone +dgzcksnqz8foursix +9onetsrtwotwothreerbv +4dnzc8 +fivenine4sjzsdgvdqsix3511 +7twofivefivefourqdgpmfblgv +oneonelgjsk9 +zcfhrrpseven8tlffkfnineeightttwoknlfdjpj +nine5nine +8sixtwotwooneoneeightcdklzjgvnqrsvvkbtfj +7one9vxjdkbhqmfbpt +6twoeighttwo +sixthreesix162 +5jhxxchf69twosxjckh5 +sevenxspmvxpmc788one +9fseven4 +vxzqgxbmtgxnm588seventwoqtmfsb9 +four8nine4ftn5 +eighteightrhjzcmxql28four +twogqjdbmmxqgtxdppchr2xxhcptq2mrvgsdccs +six24 +nqdptone3drgtwoone8 +threesixnine8hlkrj +four7pvvljkscc6hvsppgxrsixknrnrvfjqqfive +7tdnbzqqxftqtxjqxgmbdhbvsqdone22drc +59rqhzrfrps +six1scbkqjd4 +89blbn +lqhoneightthree96tppmhtpmlt7 +threeqpnsevengfx3 +sixk27lfjrvhvtsixtwo +four5slf8onefournine5 +ninehgczrdslkstltfive96bqtz5 +scfkzsr4fournine325 +5eighthzn9rjdzxllvg +1six1threedrfpflhqfour64 +fivekdtgcdsjxone8nine +7sevensevenhronepdgbxvfd5 +619nine6threetwo6 +fivehchdssjrlshfqjlptsxghzrcsfcglm4 +6two73smnqbbmsix +84fivermpjpjgkn +oneeighteightfhjtxbjc94threefrnnnncdz +lrckglbdn94eightqbfxp +mtztmbhthzone26sixgjvnbzsjfmthreevqdqrld +pnrtpgzcnznfive3eightwogkq +threevfpkrjddtpszxddckhftt6txkszsbxnn +ninecxdtmdnineseveneight5fivesd +xjvv7one +5eightfiveseven +twodpfdzvqmpzmvs7tpjnpmv5 +75fivethreesixsfqpzdonefive4 +4onefive6bsvtplblfbmnjjlb +eight75one73pjgdqq +ntcnmnkvjzpvxpmb7twokqfour1 +zd1sevenmgdrgrzvvh +65four +3kzfztjxjbseven67bnfcntfknlxlv +eightfive8xnnkeightfive +6three95eighttwonineonevkrtwonebgs +92seven2cndf +onezxphkcrsix7klrhnhdcxrpz +mgl8ldbxzdlgtwo6cdvxbp +foursix7lzcddxnjdrfqtthree7six +hxheightwoncdcrkczbninefour3lfdtgnqgcnbfxbqlnt +2pmcvctfml1one92 +nineone9eight +6crppdpp4cmngqseven3mmv +473sevensqpvvhfdrfiventgvmvrhtqx +gpnzc1rmfxqgj8nine271 +84sixtwo +frcrtsqhfour3threefivesix +bhcvf6 +seven2seveneightzqmdqhb9 +28hjjrgqklqgbm +98three +jqzjntlc541 +oneq22 +7fc92ljfmqt19 +sixzpzkgfiveonezjvrzfdcf43lbqxqseven +1two4kfxglzcdjc3dpvb +fivembfkfdq6 +nplrclbrbf5ks6five4hzzbsnine +3mkmbgxhn +seven9d +vnfj8qng +eightrgtjpdjjktwo1lphnlrtjfxtvghhbncj2two +eight66frbpds5g +3one8four9two5 +9ninefouronefcckhcdfb1mnmdsltdrsix +eightsvsix122241 +3fgpmgxcdqfourkhnrptlktrchfqbxcbbcxvjgznfjkj +eighthbhsgrqkgcxtwofour2nzj +93xnjrphktk6vshpvnftblggghskg34 +seven2sixsdvmcfgq64 +twothreefive3hrmkbmrskcvknineninebnjksp +82fourninetwothree8 +2two158threeninesix +hgltdx48onetwofvnsmmsdzjthree +k38 +ninenine4sixctnznsb3tkpx +pvfzqtgpntnfhfp47rhllqrlx22 +815qxtrghrsg +5vhfourvdblpninemdzbbgmvsfone +nine8nine6four +threebcbsmxbks2two5twon +kzpsc74qxflxpsix6jgmzgqxvsngc +7dbrsmpksixqttqsphqpd7twoeight +kffivefourdknzqsevenvkssgvhxf1 +sixeight5sljd5fourxkkxv6 +rnsjsmfcbp4twofour +zdfour5pktmsmxf3 +threen42 +stgtphmjk7onexfour2foursrpj8 +pjbgtsevenseven7zzhgxlmz +sixeightfivefourseven9bpjbcmvkrfive +hfhxfqlbqtwo4cdfksbbtlcsix +778lkffbzmpdbxjbpfoursdbp +tvpjnvtxeight1onefive3nvncq +38seven47 +five8threexqtglzmpmvbzfour +nmtsjjfvfzbhpltbbsrjphrnxhr1two3sixvp +4gbvkbfqrfgrbr85sixone +6mxqltfsxqxnpdrjkxhrp +lftdxbhhzvvhpone51six +3grhbqf5one +six9four94tthree +sevenh1bdcgdtmjqhnkzxlkxsevenonecbx +jvtwonecfksxckgq6 +zvmjbthreecbpfdvd6 +6bsvrsevenbcbcgrrhpxtvbhhfp1 +sevenfivemtmpcgml9mljnhcrdbfvksvlbpmvhs +8nine9 +mszqdg7jsrcckxn +eightseven9zzsixninexhscseventhree +eight57 +4zjpjz26dxnzfb +rmcnbnlpd3nine4gngphqfmc24 +1vvgfxdfourprlmsjmvvtxnn8seven +nineonethree6zznkfrcgzvfour +gcnjsdlhptwofourtwoonemggshpdh3eight +4eightfivenxftjch +eightthreeseven94 +twokvtjgcq992 +69psqdmgbtljjzjmpsbs1fiveoneggjbbk +3k +eightsix3seven4twosevenq7 +jlthbzsc2 +22nine8jhmktwo5 +8pzmtnlfptpjckftzrzqsrxkkcc3 +four33jfxmhcdktzhqvmkxhklxjllx +nine3lqcsbmmh4f +three514twonellp +4qhn5 +sixbmkxqdgtkbcghvpzonecfmgkpfrxv68six +6threeeightjhfsmp8mpvhrjcxzsevenone +sevens9two37fjdfrnk +jhzpvfldrbmmmglvrkz2ninelbgpdlpdcteight +qj9 +rxfhkkvheightfouronejh8238 +zfsixvbqngj1vhbvxpfk6 +vjbqvcm3 +51six38ngvq42three +7zjtcczjz79seven +five8fivexxmrn +sixseventhree3sixcsk +zninefour8tworxkfb48 +63nine3 +11eight +bxlgdzqthree2ninegqn6kvktfts8 +tvmzzlpnineztxdbkxgthree1four1 +gxcnhxone9 +8eightfive5jkqx +qcfgbpgdveighteightone7seven +86eight2five +tftbbfpsvhtwo8eight8seventwo2 +skfp8 +8hdlhh4ninenxllmthreefivebhslxkvtcp +sixbmljnmhseven4sevenmsfbsbqlzrrseven3 +v1828 +6seven53hhtj +five51lkfsrm2 +bvnrdvjnxjbfv9prx +tqbnxeight6hztrsbvronethreethreeqvh +pcbjr3cjhrqxbcvpzdmfive6oneightgt +qdeightl6four +ncprx96ninegn3 +sevenb4eightwonr +qbslkmkqlf8ztzeightpcn +fiveeightcpn7hvxmtpcsbqfvpnmvgncfbpxzhfive +3rxxcqhlp4five +threefouronevdbdmktp17 +sixdtmnlhth9onefive +fouronelxgxpvtmseven2ninesix +eightrfxrkcfive21ftlcgdcrmbsnrr +nine1fourfourxkppvqrxfdhsdphjcgnhnfnzlld +562 +4sixhj4eightzkbfpdrtzcsp2 +ddfdbdqzfshfxnseven6onetwo2 +five915b3 +sghrbfzmmrrbnone9four5rkmqgh +threedmmsdvgs6twotwochp +seven1fivesixnine9four +6dvmgsjcfour3q +cschsrvz3nkk +4fnqmnd4rnxbjvcbxpchfour +3eight9 +tboneninerzhsgqqcxd2gxhm2mhdpkjeight +vpsbgmzbjk6nineeight +sixsjbzldfive6 +qjprfk1eight7vbdshhnfive59 +dbxdgt6 +pdgghktdjhsxnblgpzmtc24onecmctldqtsc +bgfzght2szvttsdndfiveqgns3 +6ninebdnbxzmeightfivevff8pdllfour +four2nineeightvfeighttwo +fiveone3sevenhfqnfbjg3five +eight19two +fqkeightwosvszgpjvbl2xtmgmc6128six +6five6one24fivemcgpx +pmvrz6threemlhoneightdjf +7cxrgxx53gksgdsv9 +six3two +nfqffqrvkvhqfzthgxp3fivesix7gb +nlqdkgllxdvgj8xdhdfnnnfive +fournine1nineseven +four35djzxvsvvdfxbnhsixfouroneseven +9fourhntsmprtddm +fourfsix81sixvxmz8eight +3pqngffjxqpntqtl8zz4 +five325ninemfqxnseven1 +1one2gqx3 +hqsfive67rr3q4 +onefblnbfvzlzthreenine1 +96zsvdl2 +1fourjjhf1tn18 +sixfdpljnbpzxlvhncjs9threefckbgtcm +seven6ffmvnnmxl8fxskzvpfs +5tgbqdkfive +52czvkbqgztwo17ninesix +bmshtrzdcmkfour5 +nrfn25one +9two4plklcqzjftj7 +onedks4five6hdllqssixbssl +2xftcfnd2twotwo +rzxzkcdtnmsbhnncltpj62 +6snszfour +398seven58 +vstfive8869 +1fivesevenvgjrlqqlthjz1 +tpg7eightseven +gqvpptsix356 +7nineone9fournineeight +tr1threenine +tvz8xconeightfz +two11five1nine +jntkxfvt2threegseven3 +b69ztbtgmqfntdnine4two4 +threedsgrrfcpzpfivebrpjhzfhs96gxmfhkhfive3 +eighteightthree5crdbzgqvtxx6two +nine4onepxjtmbhrpklmlhcfspxrjdnd +7fivetpttvnmgzd +8lmddfzjeightxxvvcvp +loneight1three4dmzxqncjbninerbsrjxxlsb +657fourdjkhrlxjdp3ninepvlqhz +three4threekddjrfsdk3 +8xbjcnsjq89 +six8ninesixfourpcsfhnsxgrz +8twosixmvhmsps3 +six9sixeight +4seven175 +4twomspqqn6929 +71seven9eight +4znc92eight +ninetwo2blcllflxonezljhhsfivelngxk +nmbrjnsqhkxzxhmxsix1oneeight5fourseven +42kvzlcdjzxmgnpqmsmkxq3seven43eightwovms +rj5hxkldqseven +f7 +5sskjblmnbzjhctvmttwotwott +9ftmpxlbphsfxzsbktjttkxclknsbkftwo7 +3ndmzlfbsfqhxrlj2fourfive +8378vkthreemggtf2 +2hprlpkbsfzbnbpsmflxjh15one +dxvtfrhhxthree68four529eight +xgjvjddtnine1zxeightwosnx +sixblpgkznvjseven2oneskvxgngzlpzvjcxkcjgblh +bhhkfive4jgngngjfhbp8kpnjtgrmblone +8vmfivetwo9eightthreefxbvf +8738 +8sixlgnpbpqpltbqqjjxpkcdfourhxzqpmm +seventwo5three +h46ssnqlfrl8 +ninetwokrkfqhh2jbznndtchssjtbpqdhtnrhsix +254 +1nhbdtwosixonezxtnvhjnine +qxx97d1dcnqzqhsixnzbrvrksnc +fivegnxzgvmzone8fourfivethree5 +fivexhx7six87 +zngqzxpmd63bgfzjpftsjgzghdppqfqbnblt7sixone +ninemzlgnkglj1 +fiveninesixeightthree4six1 +fivesix5ninethreeqkxczhp3 +eight19two16pqdstm +mplj637sjtgzltwo +7lvs7xzmjmxjhlgdqhtqllhtzlkmbfm5 +six6kqvbjfoureight94 +one9qdjpfszz6vxbrdnntfz8btft6 +65onendmdgtr +seven368 +eight31ngsdmnm +2threetgpvcseven +nine297zqgvglthreel +7eighttxvrbjsnbcseven +rdpcnrscggv1cxv63 +2cdfltscsnzg8eightwosg +jrszpsjthree8n8bdjtlcbxtsixktkcc +dns3 +2threebpkctf +5pgzpfqntc +9pkone +oneseven2fm545two3 +9threegtctbldnnclqpdmjnps7seven +1dknxbdcvpssix413 +rzrvm77one2 +sixnttfive97jdcjvcmg +spdmkhnthreebqsmtqgnm5threedxjcvsrxbq +btzkx8ckninevffmmfm3four +hgx8fivenine2oneightc +thdfczcpnxctgfiveseven65threeeight4 +five6nine +qgtds7 +hqnzcfleight8two2 +8q8zbkjrqxzhlzgmqmzrbfqceight +nbbrrmksdm2ninefive3x +fivec2sixsixmngbsjzk71 +821one4 +5eightvpxfpnzvsfhcdtn7kdkjdpsqcl +6seventwotwogxvgvxzjbvcqcl38 +onetwo23863 +24qtzzxfhq +one7six814 +czdhrn2twoninetwo8 +one54 +foursslpnrqcv7sixtwoned +9xsptsgfplpbrtpc1sevenjrggpr52 +zoneightg6sixgfdtwo7 +34twodhthree2tqsevenvqqrxq +monektltrghq97seven +ggeightwothree5cpfvrnp48 +nine7zpcbx33bbmd +six831 +63vjlqdc5one +nine9cgxgrq8 +5sixxpeightsix +onecgpxlhhgtthreetwo3 +336 +xcdjlblthreefourqrcxbxlhsdlseven5five +9znnlhrrmb1999drzkckthreehghffcgfr +two8one +ztwogggh48 +six4pcmqkpqb +14two47vmhbsgrgdone3 +84eight2 +5cnoneskjzppm +nine8threecstfxqp7 +threecsbhnn22three9three4xphcvgnz +vjq8ninenhr7 +qcffmrfthreexgjjrdbdthree3 +eightsix5 +threeeightfcsmrvdqzp6 +sevendcpm3five4eightbthreefive +kq9one46dqnr +jbmtdqbzn5sixlnthree +ninebdz4fourbvq +phbzxtvtthreerm89 +dqlgfoursix5k3mcrkmxcp +3fivesixqrrvtsjdxtdqp14pznxpnrgkrvg +5cnkfz4lxbvbpmcfninetgn9 +mtjq8threeninefourhnzgctvtrfive +47l6784 +twopdmponenzpjfbqgt2nine1qccqx +77hspkdhqfztwomkdshrkn3nt +five7pjrslqhkzcjzhn6 +twoqvgphqs8zzmgclhsseven5eightfive +threehmkjmrqqblnrfvbpzhrsix4zvlmcqeight +6lcfjthree8ninefive54 +sevenfive558four +htbdrfh8bthreeninedrjdbjbzlknine +hkhknzrbfsevenhcvbdfs2sixcbjqzltfour4 +qrvfpxdseven2 +139msnzkfgpzdz5nine1 +rbdone3ftvrdkssvmnzjgpcbdjzdkcgbcs69 +nine58 +2ckxdtcqc5seveneight4two +qtgndtm4mrqvtgbgjf7nzhvtvjqqrdmfiverzzgn +3rchqn37tlvgtftdjqxgbvhlpclpneightfive +11sfhcntjzpnkvpzjfhhpmbtjptngpnbqthreethree6 +fivenine4cthreeeightzqlckkvs +5threekjqxkddgvzph92 +five372seven8eightthreefour +fivegjjxh15zdnbxzlhleight5fourqrpxj +84sevenvckrdpxlgzkcbpr76fjzbpn +mvvxgjfqj9five1psvtflxhkpfourdxzxhvxmthreekp +seven7pnltbp1twotwo9lfdgzpj +sevenfkrtsgrnhgfive54three8csmsg +sevendczlbgjbg6srsbtseven +onejscsevensix2oneightd +mchrcflvfj3znrzhrvbhm +brfninexxntnine83kfzbn +97tfgthreefxpv +kspdrcnvvntts8bb4sixvghhjcpt +8onedxcbnlvpntljztxs +c91drttnrsevenxj9 +9onethree9fivexrszjfxcrjdbskdmn +cjtnzpfourxspsjvmrbqclkzkdftc8pdfbfxjnvflgfkqctvcsc +5seventkqrdpmrrchxfournczqzlqqm7p +nhpbdxgzzjltdftqc5fivelgvjshonervrxmgscvhnnfl +2gcqpdcgjv +bqhzdzxb54 +nsmxljkjcmnmxvcrj7threegcrjs7 +2cninev1eightdjcztnrk +cmjskeightmjfrlfhm22fivetzmfive +8ndsix +nzrgmlcrg5r4eighthfxm4 +threeptlf3x4 +3bhd +cbmzrtglngmghmonezdqnhxxd1ctpghbfzqfivefour8 +eightpdzftbdlcrtwonine29bcgxflmf +69crzsmjfivecxcqtffoursix4two +92zghnv +fivejmdxvnf1 +1ntvtnrjmeight1onegckvcnsjnthree +ncxgppbsnhsfnhlonelfbxqzsgfjj8 +eightfhjbrlzxcgtls42sixtjk7two +czrtnfzjnjhxdxtbgtmntkcpninejtzrprsstm4eight2 +483nine +onecnxpmhjjcvdtzc71seven +5l15 +19jmkmrxbdbtz4shpdgmmhzrxtbftpgrj3plvlqdvnr +two4two +kqgtjstcpnhf8 +sn6 +grtgjxgqhv2fourbjmfnb +bfmtkqfcp5hks74fivesevenbgvgzr +peightwoninef2ninejmlhndvjd92 +1qxm +2drkgnvghqrjtfxrvnthreesevenpzzldp +four4zcmmzgbzc +4nfbpctgmx +3threemfbgthree19sixone8 +ggc1gldjhxsgvq +1four4seven824nineeight +ninefour6one5ninetwo +bpjs8rjdxpm +zggcvkzeight7onejgkhpsrdkfvfx5three +7h7lpjzsdv4six1 +6seven9one4 +sixfour6 +4hkddrmgfp +43ninecrtoneseven2qbhkkbzdltfour +85 +hlfive3dqzdvjkdd +5chpcxbjkrdzbjtwofivethreem +6ninenineonefour +5five8twoonesf2 +four1seven5pbbjgmxgxmvfzjtvr6vttbnd +zzkcpcckmsixeightnine4 +9xxzzvcsg45one +xmd3ninerxllskrl +xxj2onesixfive3six +threeseven8 +one43 +1sixthreelcbcfgbone3bzgrl5 +four12535three5 +jztxrtwo8495 +threeqhsvcvzfnsevenfourtwothreeffrz9 +onevqlxcz461five4fthree +znine5 +cch5ptlbcbh2ngnlqnrdsjv6mfhndf2 +threehblbzlddttzkrsl51eightzrj +68pgmnbz7seven +twotfhcgltpp1ntpcvrmkgd998 +seven3fourfive7eightsevendlqqseven +jqtcrf43zkktbqhsevendljgb5two +3one5threethree +vvpjcnine9seventhreeninebtzmr +jfourp7twoseven32 +2prjqnineninevjlmqkrkdxv +67six1oneddp9 +tcbcttxninenine21hrmphqrjkvtnfgchjnb3 +sg1six5sevennineone +ninet7jkrzxtmmz +ninesixtslvqck9 +dnhsp9sevenrrsjdn +onekqkvb7 +2sfflskftk +79four +jnngdkghtwo1two +fptfourseven4hjvkz3onesix +tzhtsgkcp8 +9n +six4294seven8 +seveneight74five1 +kfghjdssttgrfour2two5three1nine +5gkhgsixvlpcdmpgbjkqtjlthreetwo3one +sevenfour1tfxzgsnldk1fiveqg +187qhhqlrjx +2lthreethreexthjqcsix +cgpxkxgkmcpdzhtpc363 +sixbtkvqt3 +4twotwoqqmtb7dczgqrtsixseven +seventwo7z9fzgjkl5fjndrznc +qsgfnjqsghtwoninethree8lppsthree +threesevenkdzzvzbl2foursxrlq4sevensix +seven8bjbmcnhrcp3one +gg531 +one8sfvzplxlknine54 +dlxeightwo48fourthreeninethreeeight +sixxlglqsjtmqmgcnfvpljsevenqlgllg6 +tszncfour7one +three54three4 +qkjxzcdmxqvjngmrkpmleight83 +5twoksv49 +7six58sseven87two +fourseven6ndsgfjv8 +ppmclkxhpjpqrjoneeight8two +538 +sixlhsixfive5 +twosevenb3f2twonebpb +lxqbgl55fgzfmvtpgjbxxgffsixlkxlbvmjkkslqpkq5 +7ptnpseven6one +3mtlbfc6tx46five +99pgdmnrbjv +7twokvzlvptxcrfbfzqsxsqvxtfkcpkczkr9fjxsr +eight82lfivenine +onetwo2jvqdhkktbeight +8zhxksgcc79one +knqqz4 +36twofour +2gdssixtnineeight2 +foursix4 +49hjbscbjvbckhjmjrdbh3one +fivesixdqpnv2 +7ftwo +fourffhffkphssbxzsgeight68dvhgrb +two8sevenfive1 +dggljb5nvhpspbscfhd21 +twokeightthreeone6lqglrseven +cklfcsqgtwohptslmlgdpjktvvbbx3 +two3sixthreesevennine +7ninepnclmdnv7ninevmqoneightpct +czzbhfhhrfonetwo1ttvpgxkgsonektpnfrptjltklj4 +7sixthree1five45 +btwone3fivelfzmfxsr81oneqhkzjvt +5kmrlbvpcdrfivefourfive3 +9fsl3nine12 +1seven1seventwofivetwosix +sixzdeight9fcpzvsbtz85 +n1jmxjvgfiveone +1qsptpfbqtrl19three +5twoeight3grrksgjdkgn +1dq4sjknrp755 +2three2five +txktfive2ngqfl57 +vnrjvh1qpbbzqlgjpgrsgrqgggthreeone +sevenone8srlxqqlvv +eightsbfivefourfourseven6 +853 +eight53b3sxfvnz7 +qbhrhkhcbnsfivenszghnbhsix2ggvv +two28three9 +rltzcpbqxfive1nineone +5threedcfspjkm62seven8 +tlndznhtthree268 +ndfgfkphmn2sixjxxtlbqlnine +51eight682fivepnine +dqvrvthreesixsix2fivenrjeight +seven69 +4qlkktltwo8tqgxcninefour21 +threefour32j +4nine27ngxp8 +seven5ghxkb8 +nineone56 +two8onezonesctsttzt5 +64km6ttncd +three6six6 +threetwoeight7six7jgmhreightwocl +3sixfivehjgvqjlrsfivesix6 +fiveeight3sppjtccnineeighteightnffgtlsdj +12seven9fbqxhs9jgh4five +7dmbqrqsnckxtpt +ktvlgfzt95lfdvf4lbppfccjcprdpkdj +seven65lrjmmqdfjfourtslnhdh5 +sblgrkqccmpqhfksmg5532 +rgqzkmmv4ctgzcgvqdghmvfour3 +24rtxdxqnbvdnkgtgcbfkfbtwo +63seven78hrdnnsh +eighttpj79 +foursix6 +6czcdgdmrmzcdcfmsixfkdnbdsplcscqh27 +3333dgrd +8threeltfpfz3 +xgxddj3qkcnbbbhtvbzkmvh8 +s2pzqkldrcx43xzmxqvspm +eight1gkvlt24twothree19 +lkrzltxknd5fmjgbds2klkfgcgp3xcbxxpnl9hzfbfclrx +2zhn73 +sixone4eightninelthreeeight +seven8vlqqfjfmltwosevenfivetwo +spfkzfmssfjrsevennine8ltlrnrjbcfive8 +1spbthreeshsgmrbcp +ninefive7cnxznfmcp6nine +eight4one9x3nine +eightnine4kgxhxx1ckrqlrn +6sevenkjmfxrbhck +jsgtwonefvmcdsnqfp4fivefivesevenhkbkqcb1vgkshfnxfc +eightcvzmtlvsm49 +78four +threeoneninecjzs75 +xrxrsrh58 +1zqkhcvoneseventwohbrfbqgvp +9zfznrfvtgjfhsk +v5jcblbstnvxk +6s1 +6three1seven +75xpmzmhqqphgtrblhkcdxczcvbmg +2rqv989fourthreefourone +zmghjgrfqlzpdcqq9fjnkbl7btgf +2three3qvbfbn +fivehnklrqktnqqlqfslfjpfpfx9six +3xvskqbjzrlonetwo +95fx6sevenseven3grfncsdttt +two8twoklgnrm +two9seven6eight +7lh2sevenshfvljtphhnbhvkzxxgjjrvlq7 +ninemdgkndsevensevensix4seven +4three6eight1lkdmtbh +7rdpvbqljvnine82pmqclfive +nine6nine7seven6 +54rvpqphbpxmcfjmcspsnhrjp +eightn2skzmpmtgqhvvfxgqonevtbfsmfklzspxdrgj +nine276rzshsrvncjrdzfxbmzzlvkhdlcc +sevenfivexgznfftgthree44 +fivekltdkmm3rdmdnm32nineddsfdzpks diff --git a/day01/main.c b/day01/main.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <time.h> +#include <string.h> + +void puzzle(const char *filename, long long *res1, long long *res2); +//void puzzle_test(const char *filename, long long *res1, long long *res2); + +int main(int argc, char *argv[]) { + printf("Advent of Code: day 01\n"); + double time_start = clock(); + + if (argc <= 1) { + printf("Usage: %s inputfile.txt\n", argv[0]); + return -1; + } + + const char *filename = argv[1]; + long long counter1 = -1; + long long counter2 = -1; + + puzzle(filename, &counter1, &counter2); + + printf("Puzzle #1: %lld\n", counter1); + printf("Puzzle #2: %lld\n", counter2); + + double elapsed = clock() - time_start; + printf("Elapsed: %f\n", elapsed / CLOCKS_PER_SEC); + + return 0; +} diff --git a/day01/puzzle.c b/day01/puzzle.c @@ -0,0 +1,45 @@ +#define _DEFAULT_SOURCE + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <strings.h> +#include <assert.h> + +#define STR_LEN 1024 + +void puzzle(const char *filename, long long *result1, long long *result2) { + FILE *infile = fopen(filename, "r"); + if (infile == NULL) { + fprintf(stderr, "fopen() error: %s\n", strerror(errno)); + return; + } + + char buf[STR_LEN] = {0}; + unsigned int line_num = 0; + + *result1 = 0; + + while (fgets(buf, STR_LEN, infile) != NULL) { + int len = strlen(buf); + int n1 = -1, n2 = -1; + for (int i=0; i < len; ++i) { + char b = buf[i]; + if (b > 47 && b < 58) { + n2 = b-48; + if (n1==-1) n1=b-48; + } + } + int num = n1*10 + n2; + //printf("num:%d\n", num); + *result1 += num; + ++line_num; + bzero(buf, STR_LEN); + } + + // mutiny! ignoring feof/ferror. + fclose(infile); + + (void)result2; +} diff --git a/day01/test.txt b/day01/test.txt @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet