diff options
-rwxr-xr-x | Advent-of-Code-2020/AOC-6/build.sh | 7 | ||||
-rw-r--r-- | Advent-of-Code-2020/AOC-6/example.txt | 16 | ||||
-rw-r--r-- | Advent-of-Code-2020/AOC-6/input.txt | 2234 | ||||
-rwxr-xr-x | Advent-of-Code-2020/AOC-6/main.c | 80 | ||||
-rwxr-xr-x | Advent-of-Code-2021/AOC-16/build.sh | 7 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-16/main.c | 25 | ||||
-rwxr-xr-x | Advent-of-Code-2021/AOC-20/build.sh | 7 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-20/example.txt | 7 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-20/input.txt | 102 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-20/main.c | 144 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-3-old/input.txt | 1000 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-3-old/main.c | 86 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-3-old/sample.txt (renamed from Advent-of-Code-2021/AOC-3/sample.txt) | 0 | ||||
-rwxr-xr-x | Advent-of-Code-2021/AOC-3/build.sh | 7 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-3/example.txt | 12 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-3/main.c | 127 | ||||
-rw-r--r-- | Advent-of-Code-2021/AOC-5/main.c | 30 |
17 files changed, 3805 insertions, 86 deletions
diff --git a/Advent-of-Code-2020/AOC-6/build.sh b/Advent-of-Code-2020/AOC-6/build.sh new file mode 100755 index 0000000..6be9241 --- /dev/null +++ b/Advent-of-Code-2020/AOC-6/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +gcc -o main -Wall -Wextra main.c + +./main diff --git a/Advent-of-Code-2020/AOC-6/example.txt b/Advent-of-Code-2020/AOC-6/example.txt new file mode 100644 index 0000000..24211d5 --- /dev/null +++ b/Advent-of-Code-2020/AOC-6/example.txt @@ -0,0 +1,16 @@ +abc + +a +b +c + +ab +ac + +a +a +a +a + +b +EOF diff --git a/Advent-of-Code-2020/AOC-6/input.txt b/Advent-of-Code-2020/AOC-6/input.txt new file mode 100644 index 0000000..2b636c2 --- /dev/null +++ b/Advent-of-Code-2020/AOC-6/input.txt @@ -0,0 +1,2234 @@ +bapocnysdr +lpandcmb +bplndca + +rgi +ci +i +iv + +xdgwtsc +gtcxswd +sdcxtwg + +g +j +k + +drcmwzh +aostudi + +qziunh +hgkaslmyz + +fovlpdhurzqsway +zvciokytxbaf + +y +y +yp +y +y + +gqouslwfihtxvke +bapdmyncjzr + +ywirnpmozqle +jhapfdzuvgc + +ce +evn +yzsem + +phdcuxgtosjier +jfixnurtyopdh + +mxjs +mxkjis +jxsm +xvmbsj +sxjcmh + +sgrbtmqxpwkacnzd +brncqxtskawgpzdm +mxqjtcpzbswgrnka + +fxijprlkbhte +herpxfbikmtlj + +ltuyidqkcrevanw +whbqavirludxtye +vfirqwmsaopyzld + +q +q +q + +faxhswigtprou +xhlusnijytkrwza +xaqsburiftwh +rtahxwcsiu + +cuplrimdtxke +letpjuimzrvkcyx +cpleiuxdktmar +wrfgkubeoqxsihpntmc + +zpbjimulvrdwxsog +hfmspnuokbxe + +ctm +ctm +mct + +tvkocqebls +qcnbktsveo +fnvkbscqyeot +mbcsoevkthqj + +tyjgd +tydjg +tgdyj +dtgyj + +xgiybeuhtkfdonq +diuqvfycrokhgxbt +igfdbhpqklxuyntjo +zxqkymfohstuiwdgb +kgoutiyhfxqcbd + +wzfiaexksp +fizxyskw + +azsqntcghjmio +mgksdwpcitvxqjr + +ctwzu +jwctuzes + +bpymqfisrvtuheljwadx +iejsubvxhdmwpqgfrltya +jbxmfshuvyegwqlpridta +vpxbwlqumetdrijhfnays + +w +i +i +i +i + +fctbvjmnroypuxhlakzw +cbpnmyzrtjuavfohkxlw +znoptxwakjfucmhrlvy +nkmlrhygxcazowtpquvjf + +ibanduczjfmpt +gqimbtadcuoszjfprl +mtaizxcdjpbfu +mjfaiubcdzpt + +kdxav +maxvudr +adxv +qxavdi + +uajvepgoxhwsqkym +hwesxqvpuzgb + +lp +pl +pl +lp + +tawk +suwtc +stw +ixltp +wto + +phrawmes +bscrhki + +xhwurk +hwea +bhwe + +tuhvebm +bemtuhv + +prziuqhcye +qipyrhezcu +ueqzyprhci +yurseihcqpz + +mnfotvpzdxbaglye +nbjlomxzacfqgey +glxhuwoskyrabi + +tohbrluismcagnypqdv +duqbhylatcvosnprimg +qtpbduycrlosngivhma +nvgucpayidlhsomrbqt + +grslqxjdytzficnuo +klarqjpxfscgyouzi + +qozstka +pjnruvic +fchup + +yjautz +ajue +vlufjx +ujy + +inythxv +bhxvytin +htlnxviy + +mhcqvt +sqtvchm +htqmvc + +vswymdnahrq +hrnqvysawmd +ndsmqvwyrah +mraywhsvndq + +jtxayp +atjxp +jpraxgt +jatpx +adbwpjltx + +vbni +ivgfn +avyqtmsikn +nhwivrf + +fkygvtsbpazdjwxrmqoi +btyfwsvpdiarjqoxmg +wvqyiaprsmftgxdojb + +a +a +an + +pynvsfcbherzqiwumjaod +dsivqjmurcfnzebyhopaw +mqsvnueoihczyrfdwpbja +gjqsaiwdczpvublmnokfryeh + +drawsthnfvzylebo +jmkzqhbgicxsu + +pg +hdob +nq + +gdbxpwmtvhoaely +omvdgatwbxlpyeh +gtbyxrvwmhladpeo + +ugowlqebtcpdxz +wzobutlqgdxep +tulbvxwfadjpogqze +qubdxgztpknolwe +epztwlbxqgodu + +rsvebtycq +becltsrnvw + +tgsljhz +zhltjs +hsjltxz + +daguc +fbpudxyg +glidjuo +goadus +udjgaz + +qkpwetasjfbdvh +glixc + +pufekjh +xegpq +poewviyn +enlbvp +tpesm + +zqfiwx +zqfriw +wfzxil +zwxu +dznwktpb + +kcaomdbszyi +ildpzaqsbx +xsdqirazb + +mqebolfk +peqmgf +deqfmw + +grcqpi +dvpmqte +ohlwfujxkanbsyz + +txnhgzuwaicrfl +qtnwizslxuahocgr +mcxhglnibardwtkuz + +cvjbyrewa +wczb +zbwc +wcb + +psvotmiaqyuhdnrekw +aovnrqwsiyjmdutpehx +gaephqunbrwdsmyiltov +rmftshdpcznwiyuoaveq +pyatoimwhxeusnvrqd + +wsjvydieaurhqxofzlgpmbk +kemhzfusnpajxirywlo + +ypiz +ipz +jwiz +iz + +pxoedfk +pxogkd +tkjsdocpex + +lsoz +zxc +z +wkz +zpw + +frmcndwyeix +qritwfuymc +mzrwyfixc +mfczprywi + +ygvtslukaeoinhwd +vnepzqmcwyjlufrdobk + +bi +itb +bi + +wy +qomwberkixc +gw +hswg +lpw + +krifxwcusnjmle +cnijrwxkmspf +cnrfiegmqswkxjh +skiyrmwxcdzjnf + +ifwqlzhrudsmn +fzblomnwspjvk + +vnjsxdiobeuhcgfw +dhwienfjsobgcvux +wsinxchtegujbdvof +cioehdxvnjgwbusf +gdcsfeobjrunhxwviy + +lpzntyhsxruiqjckwv +ixyprghzqfvjsuotlw +ayltehsxubqpmwrdjivz + +r +lmb + +n +n +n +k + +lfsxwgkeioztnuydmqbc +wkosmqcxtdnluebigyfz +olekfdcyxgqtsbumzwin +kwqzfedxblcitgmnuoys +ibdetugcmfzoknwlxsyq + +c +c +c +c + +nmrohgpcwsjadkyqzl +mgjhdwcpoknsqyazr +chnajzmwopkgdyrqs +bdcnhgamkjqysropfzw + +yqtid +ujgkz +rmas +jk +og + +f +crj +cyo +neqhmb +f + +uwxc +wpcu + +bkhpcqyeljvftxnz +kpvxqcjin + +eqjzkctynvo +qyovecnjgkt +xjckqenybvhpto +jnkmezvyctqo + +lon +w +vwh +h + +zrosv +oblzfats +cuozbmak +dpyegwhnjz +oztiqx + +bvlwgjrixaskqpuzyonth +hatusdrovjgwcyipeqkmzln + +vhneajldr +apnvjderl +lynrjcae + +qodczyfijam +fkdxpgrcnmio + +oai +iao +oia +oai +ioa + +nhgewpbozmjascrk +vsocxumhryfnbqwkaj + +jxrls +sycjpwr +bdcrqenuhtsz +sravkif + +bymwecxqrloj +lhofkz +vzldo +klof +oulk + +lfxobdwcji +odbpnilxjcw + +pbcr +rcpb + +msp +esm +sm +psm +dcsm + +clkiabts +hskec +sckgf +kfncs +sekc + +dyckmholpqbtaunf +lacdqknfhuymtopb +kntfqadpjlbcyhumo +qoflmbpdhauykctn +dphmolaynqcfbtku + +whkzitxfqem +ftixzqmrwek +mitabqyxkzjwfpne +qzwekxtmfi +iztmkfwxeqd + +wxktrn +txr + +tapvryqbecdklwsjzxug +mwjgatucpvydsnqbklxr + +tw +wt +wt + +irsehx +ehsxri +rhxise + +ekwyuzsvpfjg +lcspakbhnmiod + +qifdbzapc +rwpvkbd + +f +f +f +f +f + +yskpcdmber +bnpdelmcryksu +eqcbzdpkgyrmsixj + +ibt +iez +cz +b +xvls + +d +d +d +d +dq + +ubfpqyrkhceo +yfhqckubre + +zyhnmseuivlbxgfk +nviufhobsyelxzkm + +agbdzfsqetclpw +wctbfaqeszpgdl +csbtraldqepvgzfiw + +dmatzvowqcklbgirf +ldiczavboqgwmfktr +gkaditvmclqrwfboz +dvrfntlcijagmzobuqkw +iwzrtblvdoamqkfcg + +xhjydaekowcgsmruftbpqvln +wzryxjmfdloqvskubanh + +skglcvahyx +xyp +yx + +tvsguaxobzkd +txoguzsmkbv +soegkitjbxyuzv +kvobgsztux +gtxvcspoukqfhznb + +osca +osai + +sjv +sjv +vusofja +vjs +sjv + +ipwxnmkbzhscarlejtdoufqyg +ujlxyqzkgtpfrdnihwaomscbe +dyslimrkjqxnftcpbewzuohga +gyphacbxnqdriweumloszjktf +czbroamputiwjdnqhleyksgxf + +dygktjflepbcqm +zfwsneviuo + +usz +usez +usz +zscu + +jkbies +ejikm +ejphkoi +kmjseiz +jike + +qwjvbzmypcif +hveligmbpatow + +aumeftxligdy +tylfgicdx +wlditgfyx +tcxdgrilfsy + +wi +iw +iw +iw +wi + +zsd +cbmoz +ouwbaq +ghexrpyf +asmz + +ax +w +wrd +vqclmnjfob + +sy +aumz +azs +hvoecbdfgq + +p +p +p +po +p + +sydzgpwourlbqfcj +mnzcjkeubaprofg + +kiatxsph +iphktsa +waplhikjt +thapik + +cpv +pcve +vpc +lmtcv + +eyghlrunfctbqzos +nsryfzuqtmecol + +zayxpivkctudsmgrhqfl +ynfsuctxhakdpjglmovq +fdvgeskyaublpmhctrwqx + +egymspiuwoarnlj +poidtzjyglwume + +tmlv +motv +mvthn + +vh +vh +vh +vh +vh + +vthobzjux +ojutxvhbz +vxhojbzut +zhtvbxouj + +k +k +e +k + +bkwvlpt +xormzn + +aforqletdymv +eyorqmflvdta +ytvaqoejmdlrf + +rqakhn +khrqusmaj +rkhqa + +bmyztkxldgiosnw +tsoyzwixdmlbnkg +btimzdlywknsgxo + +mqifeszchaoxjygvdrklubwn +zjdhxnboagfrc +cgarozjxdnbfph +xbnrhcjzfgaod +fzdhrxtancjobg + +gzdvh +gztvmch +zgdhv +ghzv + +yjldgioabsr +musahntecwl + +fujnlstvgcbwio +clgkwmijsupqzbo + +cqi +iqga +qza +elgyxq +dujqtkprvf + +dzrawsxvhgtflnjeikoubqypm +pryqevnbkiusghjlofadztxw +eawipgrutyohqvsbcknjzfxld +bavdzsphqugykftnjeorilxw + +q +vxoln +feq + +y +s +s +l + +gfdp +pgd +aep +pdfsb + +watcn +tawn + +l +nly +loy +gwsvl +l + +ehfqltbkvizcmpaxn +vzqkecthbmnfxliap + +l +lrx +l +el + +mznoqpxfvedutclhar +gsibywkj + +gft +dqs +rm +rbe +dnsrh + +dgwncrbfo +uboewdjnagxcr +ogrcdbnyw +bwgrdnoc +orwbcgnd + +xlnyqidbvfuopwsmetkaz +axsnipqkotbydfvuzle +zsyaohudvqweikfpljxnbt +aezfhxqipvkdtbnoyuwsl +qsneybxfzidcagokulptv + +phnrogdiuwlqtmfvjcb +sdmufyklricxpg +ifdxpmkruealgzc + +xdiushclzbkvnfw +bjmzunysickrfvxd +xciutvyksbldfzn +xfqpzabiuecnogsvkd + +olv +ovl +lov +ovl + +jirywmg +jnxmg +jfbgm +mjhg + +sjfvbhimpyauqctgx +xasifmnuqtyvgwojclp +jxyqabfuismptgcv + +spgmtcvwlxyfaq +gpnqlctymxw + +xthqemkfpyls +pqhtsymrgzoef +yskhmtfpqe + +xcsqaokhpt +hcopsqtxak +pqoaxstchk + +oqexlariumftkcg +xceqoumklaiwnhtf +xekitmlufoqcag + +zkjmutfxryowbnv +euomntlvzxiqydrgwspa +whcyrmvozxktun + +hxqncgbjrsl +bnlxcjrqhs +cjqngsblxhr +ihpsnrblcxqj + +rjtlufdmxiqkn +afmrkuindxljt +uktrmjilxnfd + +ypxqris +hpgk +budwp + +oqulm +u +u +iu + +kahocwxnueyri +rzesvkxyltmbpqg + +pkxjboidfvymngzrts +rsizgmydxkpfvbtnjo +bopgismxvrzntydfjk +ovgfdztnspyxibkrmj +oecxdvmgrfkzbnypijts + +ruvmcpojzsqtayw +rqotdwzmpjcuys +ptnscirkowujyzqfm +ocszmjwrtyqpu + +nzxqdbwvpkioaj +bqijkzpxwonadv +kivqoujwxdzpntab +inxabjvzpqdkow + +ochlv +covl +covyl + +qsoypnvewrhjkdgtb +jpgwdknqeytbhsovr +bdpwyrjuhoqgevtsnk +rkoeypwbvgjnhsqdt +qgtnyodrepsvkbwjh + +u +i +o +o +rx + +ecikgqxbyjhupozvdnrstawfm +cnuiyopkzwmsbtadgeqrfxvj +omkbnwrszvaetclqdpxfiygju +wimrdtexbnjspgokuvzaqcyf +veacgjpzmnioqksfwybxurdt + +egfkhxi +gkshf + +shiayxrwutmzf +isyatmhuzf + +tfgmicrqnpxz +jeurkptlyh +kvtphwr + +tyqrx +hotsrdyqz +yptqr +tyqr +ryxtq + +lxtdzqwcakvm +xdkqrlzv + +ipujabzkmldhfrwg +bjmpkavhlgqrwfdiz +ofhizbrtdcagljwmp +bfgvdaesjpwrlzumhi + +s +s +s +s +hs + +nobqduvlcjtw +dyrbtpzwng + +iohlwxgfs +zokfn + +uawlqejvnfkzhor +rqhkanfvexlwzoju +avqekulojnfrzwh +kljwrhonqfzauev + +ln +nl +nl +ln +ln + +qyxi +fmxbo +qxo +pkvnutje + +tjsz +zjr +gydfxcjliq + +ufa +dohwy +f +kau + +ezjqncv +jqvzenc + +pnhlasjrztw +rlswpatnjz +hpntrjslazw +zjnrwtlapcs + +i +i +i +i +i + +aovitgfucj +bowihz +iol +iweoz +iyo + +bdgmouhjvyxr +inpshdz +nhdfia +htdl + +pnzawmosg +zganost + +emrakn +glveamkr +rkgames +akfqmper +imudroeak + +tibgokrjpxmy +iydtpmjkx +dkcjpxseiymt + +imfnqegj +mcp +nwgkhmbrpjac +szovdtxl + +qnosfwmzpiubkxdhctg +msutibqnakhgczfopxw +xtnowmgicfqsuzbhkp +pwbkcqiutxfshzngmo + +jgaqubtpokrn +jpqgotluzna + +siblotrefupcmyajdwxhvn +tdxpnfrbuivjchlsawoeym + +gvbfkphuqwsrdoejlt +ixpkoqzldfncbahwt + +rdlfmyaejnswgopv +ysjfvmazeilonurbpwx +jayvlrwcmpefnos +yowvefjknltqamscprh + +r +d +d +d +d + +iry +gi +lri + +kzopchbqgf +phcifmsbgz +canbyhlvdfpg + +ljmtd +stlxdvmkjqy +otcljbfehmd + +zgkiqsjrm +rmqosfenz +zqdmrsig + +jaegcxl +delcpxa +lktzbxcea +pdclajxe + +gdrfnb +dngbqriyh +ojnbgrzd +fdnrbg + +ixnhlufgkqojyrcdwms +uvfmspygeizlkhxcawrbdotq + +cfzy +zfcy +czfy + +kfbqdvgacxnluszhejiowmytr +durgtzlkjpwnechqibxfamvoys + +njcgoslbyutihpqxwe +wrbgpdquiykhnofvecztl + +cozxyqbvugrmkdwlh +rxcdwuylztbvgmqhk +urmhkcdlxvgyqzbw + +okzsvutdehimnc +mednkuhxgqwvizots + +sogfalbukwvchqmjdtypzix +pyfazktchbmvsqguojwxild +imsgakcotjpdhuwbfyzxlqv + +yzpafqijdchrvosxkt +tqvsdrxzojhipfkyc +tsfqokvphixzdcryj +pjfqzhtxocrdkvyis + +ysmndq +qdsnm +rskilmn + +q +q +q +q + +fygruq +fxckylwohur +fspaznjvbmdt + +ztqa +a +nma +a +a + +erml +ejrm +rem +emr + +qkmpeuatxdbrcghnjlo +xnlmcohutkdbeaqvpfrj +rboxcdpaujeqhknmtl + +bpmiwjrs + +tyr +ry + +jkyolgr +dv +anwid +idzv + +z +xzpnb +z +z +hz + +mwxibru +dxrwzobi +wixqvrb +sbrxwi +baixrw + +yzcdlgujxrpmbs +iadjzpcnyrm + +nq +qn + +sbwtamevgyicuhxrlfz +uzxkpmitwvlfqhcgjn + +xvhbkanc +bozyjftqrl + +vpcougdijwlxtsmznarqfy +qyroagjdmsicwlftvxunpz +nylpitxuqdwrszamfgjcvo +amogspxyvrdniztqfuwlcj +fuoiwmpvtlxdszqncrjayg + +ocmqey +yqoce + +mvulfyk +fxyuivlmk +afvulokym +xufvjmykl + +wjz +owpfqnsrgt +ewycah +webhjid +bwi + +ucxqaszovj +xacvqjskizuo + +auxsjhkiq +zcymv + +qyljukpbitdx +pxqjlduitkyb +utbpqxjyklid +yjkdqxptbluir +puliqbtkdjxy + +ljurghymqktvpenzsbofwdxc +ofyrjptgnczlwebdxvqmkuhs +blopcvezhdsjnxgyktqfmrwu +dwmqkuhtjsofnzgbrvelxcpy + +zn +ndz +tzn +nkdz +nzvk + +vmyrlzxcwkjp +mkqlvyrcp + +xduvzyfarpkewscjqlmh +fzcyvxkmhwqreapds + +nt +cs +c + +jxraviqybmgutesdwkfohlp +hnkfweosqvbijpymuxdtalrg + +fcjz +mnwvo + +mfqnkiaj +nakqfimj +arikjubnmqf +zfqikanjxm + +pjetdfwsxohlz +wpkzntbfsdcai + +zoifjgyxkluhbrtq +yjolrgquihbnxktfz +zoibyqghrjxtkufl +iuklgxbyrtmjfqhovz + +r +r +r + +ytqzlvcwseb +bcvqntlswyez +cvqbtewyszl + +hfyj +jsbrzyhiwknfg +vfyajhd +djfhlym +fohyjux + +dzcjlgutfoipaexkmn +koetcadiuznpmljf +ctnilkamodfpzjue +cofuezanjlpktdim + +nvtjmurwhfzex +thxnrwmvuejaz +jexztumwrhnv + +r +r +r +a + +enoclavqmypruwkb +tzspyhlawuimvrq + +yxcbvjpsgt +crxgvitlzjbop +gukcdbjtwvexp +bgjcmqspztoxv + +w +w +w +w +w + +qmocdhri +qpwioderm +dvmocjruiq + +nvghcjxd +nbcvdp +nvhcd +djcvn + +yfzukw +kuywf +kwsyu + +adjzmqebokxhtuspwgiynf +fmshwkpoguljtyrziabqn +anyofkgzsbvpuiqthwmj +qfbhkytzgnwoicjsapmu + +tlmn +nlti +tyehjn + +s +r +s +s +s + +n +u +u + +tie +jet +et + +achjyurqb +jpcbrhutqy +rbjyuhcqp +ybfucqjhrw +qujrhbcy + +o +o +i + +migypa +pyimag +pmgiya +agypim +yaimgp + +kdzafylcnst +aznrtshxgylcb +cstzyaln +anetplcsyzq + +hilubmsyznrtvqxpjo +yqbirxnpzslojvtumh +tyxlnibhzmsovrjqup + +zloiuyekfpx +aqtxzmig +wsgxinqbzj +bavthrdxsiz + +acwdny +ghrxysndq +ovdncy + +p +glxy + +ksnzbjyxgwtvm +nbwzvtkjysgxemro +bvnykztsxjwcmg +qyzbmxjhtakgnwfdvs +xzjmbsevgwytnklo + +uolyhfmwcpnk +ykuchfolpnwm +lnckhofpyumw +ylnfuowmrcphk + +oumqj +ulzybvfsp +um +u + +zh +gh +zh +hns +hg + +xlvaqwncsizrbopukyegdmh +lxmsgzqyothupikvrbn + +lhqdviu +qafnemdvlzbrpk +qlvyxdw +sdluoqygv + +v +v +v +v +v + +blqcsyup +clmpubs + +noumlji +nouji + +wkvj +d +ghy +x +k + +ohbjykuena +jbyahkpez +jyafhevbk +yeajhkb + +auqjksywpcthxf +zchkqmanpd +kvaephqcn + +ygrvwtleidhapqcoxjzkbm +uvmtjkcxphybegzqrawiold +dpckejybntqgvhzaomwixlr + +wuvknho +wunhkv +awhuixnkv + +xtsglwhpkozumein +tiwzoklpxheumsgn + +kdicmfpsejygzlraqh +rgpqkamdfecyiljzs +fgjrczaedymqliksp +adlgcpfieqrmsyjzk +mfwincakdjelorbygqszp + +jhtufzbolnrpgiv +rymwi + +bcdfkrgujzqwheptivls +wlzfyvtimksqcdujngorb + +eruyigjwb +wojeybiulrg +ygujbwvzei + +fizsg +jnue + +yalxikzg +iagxkz +xizkga +zikaxg +ikxzag + +pjzlhqwixksnovbtygr +ljnvgzykoswbtrhm +rjtnogykswczhlbv +ychwztvrgsonebaljk + +wcmyzldhtfrposgnj +fcrmtyphngjlzs +gpalbicyvfnmjxekrz + +ysmpe +yemps +stype + +meruv +mbrse +ryvmsei +laremdjq +bremck + +jaeutopnmdhvfklscirqgx +selpyhdginkxfouq +difgepshqlukonx + +oyz +yoz +yoz +yoz + +kohdfzpsj +rjkphfdzog +jopfsukhbdz + +cpvr +cvy + +xavdpsto +bweoysidhp +rndplvsukoca +odgusp + +ofzgbwqdnkjp +vcbnlqwofisg +enbrymdqpogjwf + +ukrdtiphflv +fvdlnuirtkh + +s +s +s +ms +s + +smodvglcpenzbtw +vgwcmfdnlobi +dobmzclwvng +convbglwdim +wrcojghvdblnmx + +euy +iey +hrkyowpesz +qeuyn +ylfe + +jd +ygd +d +d + +ifxlcevjr +muqybvdntl + +hpjdqw +wjcmqdp +pkojqud +djpqm + +fz +z +z +auzlgh +zf + +oadfixtrspzymgkjvhc +kureodwxjzvqcagmflt + +umdbplaejicognthw +mldwpqitgubajnecho +gdrhabsmketcwpolunij + +utpjbioagl +pujgaobsti + +wzqkmfigsenp +btdpmnrhaix + +g +h +fmy + +qfdshywubmn +asnjyumvhfepqwbd + +tko +k +ki +k +kvj + +ajrftpclemziyx +tyfcpmzxjrael +rlymxejactzpf +xpfzalrmjteyc + +lngatvoimxerfs +xvsyefntoli +ixvdqstzlonbefk + +dytmarichvj +tvhdurymj +mefohydrtjpvx +yajumrtvhd +mjrvthdy + +mdizkcbhuqxfpew +lciqkhpdzwumfxbe +dmwbhzqpojuexikcf + +av +a +a +a +a + +buwiq +wbqi +bqviw +wbjifuq + +szyogteivkjmubnl +gnmeioyhdjzkutvwqb + +vetwlrjnzuxfamsydoqbhpcigk +lhagxseotdcqbyrwnpfkizmjvu + +ikt +sxuik +rigbk + +ixzofbapunser +umbfxasovni +oansfubxi +xsoauibnfk + +ebzhanm +rsywcgfuaoqxjvz + +dygrvauxpemhosqkwtfji +pxafqktysdjvgriwuehom +ikurtagpdqswmfjvhyxeo +mhqlyugsravkxoptdwzfjei +wejrsutgikxqpfvydhaom + +ynam +ny +nys + +exwzkcjqnvp +ekpzvqxjwacn +wqnjveazxpkc +zjvbqkwcrnepx +ecnvywqzjsxkp + +qmfe +qmep + +dlwymbrsvgxefi +gxeyfiqmr + +mjgkdnbqzcrtfvue +ujgvnrtedqkzfobmc +nerkmbcuztivgfdpjqy +bktnacmqvjredfuzg +jgdecrktqnbvmufz + +desyfjcwkgpabomrxluq +uecwxsrgybalkpqofjm +gmlaojpwqxsebufrcyk +sxfoakcyjlmrghqepwub +gmwouepvzjsirxaylfqbkc + +lugbrcezj +ekzuhpxtl + +bzurvkdm +gkzbdvmuwq + +vihtwalesoqmgzrfub +dqogrhlvueimaszbtw +lmbiwygzaenursotvhq + +fagwlnujrsv +ujhnvmcrpsqwl + +dsoq +odzqs +oxehvgqunspa +smoqd +dsroq + +lw +qnlwbze + +zcs +dpalw +oqevmritxf + +hw +wh +mhz +h + +xwpkgiureobdvamtlcs +sumvltgxoerdpwbacki +faozilpxetcbvwnsrkugdm +dioulrkpawstcbxgevm + +cfziqrvtghejx +zahecstbvjrqy +gcqrzvjnteolfhd + +jronwks +kjwrso + +xtfp +aqwzv + +gjvrecbxaqns +koficxqpjsvnalzb +vcjbqxtunsa +bvjxnqcas + +n +n +k +if + +hnzquyjxadotim +ctrmnlvfugjkoziqy +ubnfoyqctmzpij +gyqzvjwimunot +nzmoluqikjywt + +wykxduqrzl +drklx + +xdr +xrd + +sdrbokn +rsnbdkio + +qespuyziargjdlwnkbv +iaorexbukcmtnwhf + +gti +dit +itb + +tzmwbguraxjcieodnf +gmitqzdsnekjoxaf + +kdeziwsnf +lgzkiwen + +fbvikdpshltegu +kpfvidlguehtsb +gdysepktuihlvfb + +jzegrfyducaospkltvwq +crzgkleptvuwsfyoqjda +rogqtajuweylsdfkzcpv +zwacrlsptgqfoveydukj +ufokdrzglqjcewtaypvs + +hsqnofzvt +ahvpn + +umaznoshrwf +hzosundfr +ushfnzor + +w +ie + +byandqklvw +wadvyxbqikn + +xspcwfvnkuoydagthjmzbq +ahnprtxeojdmgfqvwzuikscyb + +txpwbvjacrzifgshyluo +hgytapvojfsbrxwilcuz +wpvxzshcrabfjtygliou +bvourjgzfytpiwchlaxs + +ufesbdavpn +siunvefpdab +nspafhdvbue +vednpusafb +sufvpbande + +lnzxudorwykfqs +vckufbqxhwjmtga + +twz +twz +twz +tzw +zwt + +nuaeqphyvo +ovaqetnphu +wvhulnpsxroqi +ntvqephou +hyvuqpon + +szky +kz +kz +kz +kz + +uekpcxjqrbzy +ewiyrkobtl + +rghuyp +ntyzexi +yjnq +sy +eysao + +yohactxlqbvsfe +yacfqtxlsvbeho +qxtaesbfhlovyc +ybotxfqschvela +tsxbqlcyvfohea + +crvkbef +efbvkc +erfvbkc +fvbikec +ecvfkb + +eziafud +odfeiz +feizd +rmeflzidc +zeifdo + +uh +u +u +u + +slzwuvhqnbpogia +bhviznawou +ufazbvinhwo +ariwbuvzhon +vawnobztduhif + +lyi +syi +imy + +igx +qfz + +yugfqtepvxwdocijlzmhka +ymdleizpjgxcvtfhoakuwq +utenhymdcgjqzlorxfvakiwp +zwlvymtgfxeqcopuahjkdi +auzpqtcifejhomdklyvwgx + +xfvdiwqpktjlaborgez +mlcubagjpwzynxekqfiotd +fadoezjwqxtpgbkli +osldxpzbqeifajtkgw + +mfxjtn +pqesvmxf +xmbojhft +xbmafc +acbfxhm + +bsua +uasb + +dtmpiwjkuahzryfvqgx +iavzqyhgmrxwtdukjp +thzkaxwjpydqmviurg + +uabgmyoidlekzcqnfvxsrw +kcybroagdmufqxiseznvl +eroscxuqvglanbikzyfdm +gfmdeibnkvuaqryzloxcs + +wtmds +cxm +wqdrmz +voahgpkfml + +qmougypvzh +yoqsgdpnmhuz +gauxyzpkoqmjbwfl +qguzoivyrdmpt + +uyerotgj +wqszinpyv + +rosx +ors +ors +osr + +dtcuiwlse +bgaosqntxuwfpvrc +uymskctjwz + +cshbnzoduxlpfrayj +hcasypofnrxblduj +pjyuoxrfbsaldhnc +uharfpoxcdysbnlj + +bsklgcdmpxio +ojbpdlcmtugskx +exdkmpboclgy +aipogmwxdkrclb +dilmqcpkxnwbgo + +xsajoug +pxujgatso +guxojsa +mbxuwzjosga +pxjsugoa + +tgfw +xemdgvyfu +jfga +lfg + +khvg +kghv +vghk +ghkv +vgkh + +xfogcwnvkey +kvxwomyfeqc +woxycvafkbe +yovafwxcke +ekvfyxnwco + +ezpfkoxycuwgimqvabdtjnsrh +nmpoxgwdyruecazsfjbhqktiv +qtjzmaycsgnibdxeuwrfkhvop +yfaqredhbxinsvucogwtkmpzjl + +mhlnsrfadjpekczwquvo +vsdneluworhbqjfztamcp +smthfdwjznvqpclogaure +cevkfuzqxjmwrlasphnod +ijrnwqpvudzalfoesmch + +icmdtnrpq +tmdqnirp +mdintrqp +rtpmniqd + +clspvk +xclpsw + +rmdoajtxvc +vurmjotdsa +mdrovatj +nadvmrjlot +drjotavm + +kl +hfjkblv +cklr +lrsk +glk + +xpoawenkc +yrkpnzjocxue +pskncodex + +b +b +bq +bh +b + +kngbuqcyijvxeh +kbcmngjshaxiyve +enybjkvqtucgixh +zhrevfodplyxnwikjgbc + +vizojfmup +mfzhjqpuoiv +uvtmfzipjgol + +ysobmzkthjdw +qlncxwamrtujevfpzgbhkdo + +gz +gd +ickxr + +brenfplc +rzpvwumik +rjctp + +hfwcruyoa +ihyduxfw + +zlumthynfkjixo +kgxnbhztfyojmli +kifzxhtlymngoj + +rqpdbzgjsowakvt +gdzoyhjetcfbqkl +nbjgqftozkud +zxbogjqktd + +writbe +etri +dtfkern + +ctwyqdi +j +me +nkgzau +sxkare + +qlwakzuxsnfjc +ufzkhmwax + +njuysxmhdzivfgqb +uamlqxdhnyvgjibfz + +eigl +lige +elig +geli +legi + +vrmhebiqupxoclfatdkg +ytaoiknwcgrsdzevxj + +rhac +dcajbr +oxizsuykfvlwn + +a +na +a +nka +zdua + +zedtlhmj +yqoxn + +wyqhegrp +wypqhegdr +unrypgwqhez +hypqrgbwe +yrgpeqhw + +mxjkhbqgwuniftedzvcl +jciqfnbeumlkhgtvzxwd +njwquxidvbhctzmklefg +hqfwtcmkuxvbjdelgzni + +lsigyrmjndapwtehux +mtwpirehgfxuasdjnoly +hpdlgjnimeusbtyawxr +agywjlsmktzihxuceprdn +njwhigapyexmdlutvrsb + +wiaejbsdzncytol +cjelwafyindtbzos +zalobneisywctdj + +jbsipuwdcyth +thbauysdcgpiw + +bw +b +o +lr + +ojkmnthfzlvg +vhpzmgtonw +yjovmnfwthz +fnzhtmoav +zcosivnmhdetx + +hdkofir +kanxoflugziyd +kodfcrwi + +qxpmckuelwtarij +spxmvqwjrileckuat +tuiqrajpwlmekxc +taeupwljxricqmk + +dn +dn +nd +pnd + +fvyxadu +fwxmny + +vsxgc +vscxg +scgvx + +wovudbian +dyeosauvinbw +auvdwinbyo +uaxoqnwirbvzc + +aosvcdn +osna +sano + +shqt +sqth + +ktlracvqpeju +tukcwearql +trealcukq + +rsezcvdbal +zebvamcdrp +cbedrvafxzn +vxnibedzrac +dbirvczae + +gbpzy +ubglkzp +pbgz + +jtxhnfge +xgfhevjtwn +tjhngfxe + +pvodec +goedfvamlx +eyovd +evdorpn +vedot + +lsyqpjuviohbz +luzjybidopvx +yiplobzvj +zobwtpjlvnyi +bzoilvpjyu + +cevybwgdmuahsqzp +ucpnimw +owunkcpm +pmwoucf + +uqchtxvoaze +ehocxtvza +cetazvhxo +ztvxcaeoh + +cgsonqxtdfwhzymv +qbkncfmuxapdwl +mfxjztcwryqdne + +zbkyrc +ckrzb +crkzb +zkbrc + +mca +cam +mca +cafm + +z +z +z +z + +zytoupbkxdhmgcsflweai +smpikvyzcxlawobhefudgjnt +dolpihwzxqckmaufytgbse + +ktsr +ktfs +itsxvkb + +n +i +aklsuty + +wkgtem +mewgtk +gkemwt +emwgtokb + +mbuxkiycz +fhronqjexplgwa + +hu +emlw + +vkuwrqnj +hys +mzet + +fmclnjvsaexpkg +zjwpxevkmacsglf +xsamjlvkcenfgp +vapjkcmglxefs + +legmbjuqsdkihtv +dlsqkegihbcjtvm +hqgdmvljsrktebi +ehlbvgidqtjkms +btmshvdikljgqe + +k +kr +lfi + +obmup +ubm + +azqdrvjimbfnoyp +zbejcqxfkotplndv +pbojdfsnzvuwq +gjpounhvqdfsbrz + +minxopwrsbvqegyuajcdth +oahnukmgepbtdriscxwvyj +xmbtcwgrasnozhdjiupeyv + +jitgzlokacv +vzkushynclojtxgep + +ntj +ntj +tjn +jtn +jnt + +gdzxykoialsqurtj +kigupewoxqjaztcdy +zugyaqksiojtxd +hyjqxgzdauktio +kygqutaszdbxjoi + +orsfkumexiq +rsbjepxmi +smrxqgeik +arnsetyiomxv +mwighaxsdrce + +mcuzkqvsdpltxe +pklvsuexmgqwizd +zdqxseckmtyvlwgrp +dvslkezanoqxmpb + +tcbqprkjgnihzs +ivgmxyzaernhwcqdjlt +otqhfjgcunsrzpi + +omqbwvktlsxjcfzaphyeid +zijtkyxhqvowpulmbgenrdca + +igrz +irzg +rzgi + +kefw +kewa +akew +xtekw +ewkf + +lvxahjydcer +sobnzgkp +musqfg + +orijnpvwm +obqzv +ulvo +ozuvt +zcbolkqv + +ouzpgsxejbmqkat +btiuxyojspgzqalrek +ekbqupzaxfotjgvs + +t +tb +t + +ksyegbpm +slmpgdetzbk +gbseumpyxk +ekvphnbcjgms +wgqrmispobkefa + +gwexf +wfxeg +xwfeg +gfewhxb + +oephijmkngbxw +kxobwjhiegpm +wehixbgkjmop + +rmvtujdxhki +lkunxhme +mafxsbhuogkypw + +rpimb +prbi +ipbr +brpi +ribp + +hvjdeyw +jhecqpbyvsdw +wvhdjye +wvjedhy + +uodmbcpvr +wvhk + +j +j +j +j + +crzngwqm +zqgrwnc +rcgnwqz + +xstoyzgvaefqclbuhi +ywbmiguzthefkvqo +pcuezdviyoqfbjght +ubigqfztyohve +zovpgfueibjtqsyh + +qatefihbypn +xwvskd +EOF diff --git a/Advent-of-Code-2020/AOC-6/main.c b/Advent-of-Code-2020/AOC-6/main.c new file mode 100755 index 0000000..7fa135e --- /dev/null +++ b/Advent-of-Code-2020/AOC-6/main.c @@ -0,0 +1,80 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if 0 +#define PART_1 +#else +#define PART_2 +#endif + +#if 0 +#define FILE_PATH "example.txt" +#else +#define FILE_PATH "input.txt" +#endif + +int q_answ = 0; + +void parse() +{ + FILE *fp = fopen(FILE_PATH, "r"); + if(!fp) { + fprintf(stderr, "ERROR: Could not open file: %s", FILE_PATH); + exit(EXIT_FAILURE); + } + + char questions[26] = "abcdefghijklmnopqrstuvwxyz"; + int answered[26] = {0}; + +#ifdef PART_2 + int ppl_in_group = 0; +#endif + + char line[32]; + while(fgets(line, sizeof(line), fp) != NULL) + { + if(line[0] == '\n' || strncmp(line, "EOF", 3) == 0) { + for(int i = 0; i < 26; i++) { + #ifdef PART_1 + q_answ += answered[i]; + #endif + + #ifdef PART_2 + if(answered[i] == ppl_in_group) + q_answ++; + #endif + } + + #ifdef PART_2 + ppl_in_group = 0; + #endif + memset(answered, 0, sizeof(answered)); + continue; + } + + #ifdef PART_2 + ppl_in_group++; + #endif + + for(int i = 0; i < strlen(line); i++) + for(int j = 0; j < 26; j++) + if(line[i] == questions[j]) { + #ifdef PART_1 + answered[j] = 1; + #endif + #ifdef PART_2 + answered[j]++; + #endif + } + } + + fclose(fp); +} + +int main(void) +{ + parse(); + printf("%d questions answered\n", q_answ); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-16/build.sh b/Advent-of-Code-2021/AOC-16/build.sh new file mode 100755 index 0000000..6be9241 --- /dev/null +++ b/Advent-of-Code-2021/AOC-16/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +gcc -o main -Wall -Wextra main.c + +./main diff --git a/Advent-of-Code-2021/AOC-16/main.c b/Advent-of-Code-2021/AOC-16/main.c new file mode 100644 index 0000000..baa6501 --- /dev/null +++ b/Advent-of-Code-2021/AOC-16/main.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <stdlib.h> + +#if 1 + #define FILE_PATH "example.txt" +#else + #define FILE_PATH "input.txt" +#endif + +void parse() +{ + FILE *fp = fopen(FILE_PATH, "r"); + if(!fp) { + fprintf(stderr, "ERROR: Could not open file: %s\n", FILE_PATH); + exit(EXIT_FAILURE); + } + + fclose(fp); +} + +int main(void) +{ + parse(); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-20/build.sh b/Advent-of-Code-2021/AOC-20/build.sh new file mode 100755 index 0000000..f308db6 --- /dev/null +++ b/Advent-of-Code-2021/AOC-20/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +gcc -o main -Wall -Wextra main.c -g + +./main diff --git a/Advent-of-Code-2021/AOC-20/example.txt b/Advent-of-Code-2021/AOC-20/example.txt new file mode 100644 index 0000000..8fa4bd4 --- /dev/null +++ b/Advent-of-Code-2021/AOC-20/example.txt @@ -0,0 +1,7 @@ +..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# + +#..#. +#.... +##..# +..#.. +..### diff --git a/Advent-of-Code-2021/AOC-20/input.txt b/Advent-of-Code-2021/AOC-20/input.txt new file mode 100644 index 0000000..b40d613 --- /dev/null +++ b/Advent-of-Code-2021/AOC-20/input.txt @@ -0,0 +1,102 @@ +#..##...#...####.......#...###.#...#.##.#.#.###.##...#..#.....#..#.##..#.....#...###.......###.###...##..##.#.##.#.#.......##.#.#..#.#...##....#..#.###...#......#..##...##.#.##.##.###.##.#...#..###...###..###.##.#..#..#.#.#..########..#.#.#.####....##.##.#.##.##.#...#..###...###.###..#...##.##..###.##.##.#.###.#...#####.##.####.####.##...####.####...#.#.##..#.######.#..#...##.#.##..###.##.#..##.##....##.###.###..#..##.#.#...##.#.#####...##....#.##....####.#.####.#####.#....#...###.....#####.#...###..#.####. + +.##...##..####.##.##.#...######.#.#..#.#.#..#.#.#.##....##.#..#..#..####.#..########.##.###.#.##.### +####.....##.#...#.###...#.##.......##.#...#######.......#..#..#...#.#.....##.#.##.####.....#.###.#.. +........#.###.#..#####..#.##.###.#..#..#.#..##..#...#...#.....##..##.....##.#####.#..##.#..#.###...# +..#.#.#.####...........#...#.........#####.#.######..#...##..#.##.#..#.....###.##.##.......####.###. +..#.....###..#.####...#########.....#.#.####..##..###..####.#.##..####.#.###.##......#..#.#.#.#..... +.#......#.....#..########.####....##....##..#...###...#.#####...#.#...#.#........##########.##.##.## +###..###.#.###....###.....##....##.#....###..#....###....####.##..#...#....########.##.#.#.#.......# +#..####..######.#.###..###...#......#######..#..##.######..##.#####......###...#.#.##..##.##.#.#..#. +#....###.#.##...##..#.######..#.##..##..###.##....#.#.#....#..####..#....#.#...##.##.....###.##..### +.##.###..#..###..##.....#.#....##.###.#..#..##..######..##.##..##...#.###.#.#...#.####..#..#..###.#. +###..#.##..##.#.#......#####....##..##.#.#.#.##...#.##..###....##..###...#...###.########..#.#..###. +.#...#.###..##..#..##.....##...#.#...##.#.###.##.#..#.#.#.###..#.###....##.....##...######....#.##.# +#####..#####..##.#......#.#..#...#.##.##.#.....#.##.#..###.###.##..###.###.#......###.##..#.....#..# +#.###..##..###..#..#..#.#..##.#.##.#..#....#..#....#.######..###.##....###.##..#.#..##.....#####.#.# +...#..#..##...#.####.###.....#...##.#.#.####.#...###....#..##...#......#######..##..##..#...#..#.### +...##.#.#######.#.#.#..#.####.##.##..###..#####.###..#.....##......#####.#.....##..##.#...###.##.### +#.#...#.#.#.#....##.##...#...#.....#..###.##..#.#.#..#.##..#..#######.#.....###.######...#######..## +##.#.#.#..##...#.##.#.#..#...#.#.####.##.##..#.#.#.#...##.##..#....###..####.#..#.#....#....#######. +#.....##....##.......##..#.##.#..#.##.....##.#.......##.###.###.#.##.#..#..#.#....####..#####.#.#.#. +#..#...##..###......#.##....#.###..####.#..##..##.#.##.#.##.#..########....####.##.#######.##.###### +###...#####...#.###.#.#..#....#..#..#.....##.#.##.#...#.###.#.....##....#.##.#...###.#...#.#..#.#... +##..##...##..#.###.###..#..####..#...##.#.#.###.###..#####.##..##.#.##..###..#######.##....#.##.#..# +.##..#...#####.####..###.#..###..##..#..#.##..#........#..###..#.#....#.#....##...#.#.####....#.##.# +#...#.#.#####...##..####.###.#..#.##.#...#..##........#.#####...#####....###.#...#.##.######.##.#... +#..#..#.#.#####.##.##.#..######..##.#######.#.#..#..#.......#..#.####.#...##..###..#####.###.#...#.. +..#.#.##.#.......#.#.#.#.##.##.#.#####..#.....####..#....#.#..########.#.#....#....#.####.#####.#.## +#######.###..#...#####...#####...#.#.####.#......##.#..##.###.####..##..#######..#.##.####..###.##.. +#..#....#.#..##.####.#..#.######......#.##..##...##........###.########..##.#####.#..#..######.#..## +#######.###########..##...#.#....#.###..#..#...#..#.....#.##.##..#.#.....#..######.####..#.#.#....#. +#.###.###...##.#..##....##..#..###..#...#.##.####.#####.#.#######.#.#....#....#...#.##...##..#..#... +.#.####..#####..##....##.#.....#####..##.#.....#..#...##.##..#.######....#..##.######....#.#..###.#. +#..##.#.##..##.#.....##.#...#.##.#######.###.###.##.#...#.##..#####...###.##.###.##.##..###.#..#..## +#.#.#.#.....###...#.###...##.#..#..##...#.#....#.#.#.#.#.##.......#.#####........#######..##.#.....# +#.#...#.#.##..#.##....#.##.#.#..###.#...#..#...###.##...#...###...###..###.#.#..##.#.#.#.##.#.###.#. +..#...#.#.#.#######...###.#.#...#..###...#.####..#..##..#.##......#...##..##.##..#...##....##..#.... +..#.##.##.#..##...#.#.#..##..###.#..####.#...#....#..##.#.#.....###.#.#...#.#.#.#.#..###.#.#.#.##.## +...#...#.#...###..##..##.#......#.....###..####...#.#####.###.##..#.#..#...###..#..#..#.#.##..###.## +..#..##.#..##.#.#....#..##.#......#.##.#....#......#..#...##.###.###.#######.##.###..##.#.###...#... +###..##..###.#.##....##.#####.####.#....#.##....###..###.#......#.##.##..#....#..#..##.##...#...#..# +.####.###.#..#####..#.####.#...##.#...##.##.....#.#.##.####.#...##...####..#..#####.####.#.........# +##....#..#.#..#...#.###.#.##....#.##...#.#...###.##.#..#..#...#.###.###..#########.#..#..#...#...##. +....#.#...###..#.##..#..###.##.#.#...##...##.#######..#.#..#..#...##.#..#..#.#.#...##..##....#....#. +##.###...###.#...##.....#.#..####....#.##.....##.#.#...####...###..#...##...##...#.#.#...##.##..###. +##.##.####.#.##..###.#.#....##.##.###.#.#..##.###..##.#...#..#.#......#.#..#...##...#.####.#####...# +.#...#####.########.#..##.#####.#...##.........####.####.##.#.#.#.#..##..#..##..#...###.###.##..#.## +..###.##...#..#..#####.##.######.#..######.#######.#..##..###.###......#.###.######...####...##..### +#.##..########....#......#...#...###.#.###.....#.#####.####.##...##.##...#.###..#.########.#......#. +#.######..#..####.#.#....##....#.#...##..##..###..#####.#.#.....#####.#.#.#.#...#..#...#####.#...... +#.....#.##.......#...#.#..##.#########.###.#.#.#.##.#..####...#.####.###...#.#.....#.#####.#..#.###. +##.#.#...##.##..#.....###..#....###.#..#.#...#..#.##.##.#....#.####.#.#...##...##.....###..###..#..# +.#.##....#..####...##.###...#..#...#.#..#..#.##.##...#.#...#..#.#####.###.##.........####..##.##.#.# +#.#.####.#.#..#.#..##....#.##.#.#.####..#......#.##....###.###.#...##..#..#..######..#.#..#....#.#.. +.####...###.##.##.#.#.#.##.#.....#..##.#.###.#.##...#.#.#..#.############..##.#.#...#...###.#..###.# +..##.#..#.##.#.#.##.#......###..#....##.##..##.#....####.####..#.#.#.##.#...#.#...##..##.##..#..#.#. +###..#..#########.##.#.#.##...###...#..#...##.#.#.#.###..##...###.##....#..######...##.#.#..###.#..# +.#####...##.##.##.#.#.####.#.##.###..##.###.###....####..###.#.####..##.####...#.#......##.#...##### +##.##..#..#.####.....###.#....#..######.##..###..#.#.##..#.#.####.....##..#####.#.#####.####..#.#.## +#....##.#.......##.#.#...##..#..#...##.#.#.#..###....#..#..##.#.#.#..#..##....####.###..##.#.##.#.## +########.##.#.##.##.###....##.#..##.#####...###..####.#...##....#..#..#....#.##...##.#.#.####.#....# +.######..#...#.........#..#...#.#..###...#.##.##.#....##..#.##.##..#.####.#..#####.###...#..#......# +##.######..######.##...#....####...#..#.##.#..#..#..#.#..##.#..###.#.##..#..#.##.###.#...##..##..#.. +##..#####...##.#..#...###.#...##.#####.##..#.....##.#.#.##.#.#.....###.....##.##...##..#..##.##.#### +#.##.#.#..#....#.##...##.####.##....#.##.#.##.....#.##....####.##...##..#.##.##..#.#.##.#.####.##.## +...#...#.###......###...#..######.######.##.##.###.#..#...#..#.#.#.#.#.#..###...#...##..###...#.#.#. +..#.#.##.#...###.#.##.###....#......#.#.###.####.###..#.#..#.#..###..#.##...#######.###..#.#.##..... +..#..###...#.##.....#..#...#.#..######.#######..#.###.##.#...###..#..#.##....#..##......#.#.#...#.## +#......####...#...###..#...#.#....####..#.#..........####.###....##.#.##.....#....##..#..#....####.# +.####...#.##......#####.###........#######.#.##..###.#.......####.##.##.##.....#...#....###..#..##.# +....#.####..#.....##.#..#.##...####.#.....#.##.#...#..####....#.#.#.##.#...###.#..#...#######...#.## +##.####...#.#.#.###.#.###...#.....#.#.....#.#.#.##..#....###....##..#.#.###..#.#....#..##....##..#.. +.#....#.#.##..####..######.##......#.##...#.##..##....##..##....##.######.#.##.#...##.#...#.##.##... +..##.##.#..####.##.###..#.#.###..#...#..#..##..###.#.....#.......#..#...##..#.###...###...#..##.#.#. +.#.##.#.#.##.#.#....####.##.###.##...########....#.###....#.##..#.#...#..##.###...#.#..##.......###. +#..#..#.#.#.#.....####.###.....##..#.####...###..##..##..###.#.##....#..#.##.###..##...#####.##.##.. +###.#..#.##.##...########..#..#...###.##..#.#.#..#.####.###.###.#.#.##..###...######.###.#.....##... +..#.##.##..##.#.###...#..##...#.......####.......###........##.##......#.#.#.#..#.####.##....#.##... +#.####.#.#.###.#####.##...#..#.#...#....###..##..######.##.#.#.....#.....##....#..#......###.####... +##.##........#.##.##.#####.###.#....#....######.#.######........##...##.####.#...##...############.. +#.#.##.#.###.###.##..##.#.##...#####...##.##.#....###.#..###.#.#.#.#.#..#..#......####.........##... +#......##.###.#..#.....#.#.#..##..##..#..#.#####....###.#.#..#...#..#.#.##.##.##.#...#....#.#.#.#.#. +...##...##.##########..#...####...#.#.##..##....#.#.#..##.#..#....##.####..#.#######.####...##.#.... +#.###..#####..##.#.#..###.#.#.#..##..##.####.###.#.#..#.##.#####.#.#########.##.###...########..#..# +.##.####.#....##...##.####..#....#..###..##...#.#.###........###.##########..##.....#.######.#.##... +..###.#..#.###.####...#####...##.###.###.....#....####..###.#...##.####.#.##.##.#..#..###.#...#.#... +#.#...#...#..#..#...##.###.###..#.####...##.##.#.......###.###.#...#....#.#..#.#.#.###....#...#.#.#. +###.##.#..######..##..#.#..#####...#...#.##.#..##...#######......##.######...#.#.#.#######.####....# +#..#.#######..#..#####...#.....#..#..##.#...#...#.##..#####.....##..############.##.###.##.#.####.## +#.##.#...#...#....##.....###.#.#..#.#..##....##.##.#.###..#.###.##.#..#####.#.#######...###..#..#.## +##.#.....#.#.#..###..#..####..#..##.#.#....#.#..##...#..#..##..#.#.#..##.#.##...##...#####..#.#.##.# +.##....###....##.#.#.##.####...#...###...#..#.#.##..#####........#...#..#.##.##.#..#....#..#.#.#.#.# +.#######.#.##..#.##.#####.#######.#.#......#..#..#..##..##.#...##.##....#......#...#.#...###....###. +....###.#..###...#...#.#..#.####.##....#....#####..###..#..###.#....#.#.#.#.#####...#.#...##.###.... +..##.######..#.#.###.########.##.####..##..#.#.....###.#.#.####.#...#.#..#####.##..#..#.###....#..#. +.##.#...###.....#..#.#...#####.#.#.####.....#.....###.#.####.#####...#..##.##########.#.##########.. +.###..#.#.######.#.##.#.####.#.#.##.#.##.####.##..#...##..#######.........##..#.#....##.#.#######.#. +##.##.##..#...#.###.#...####..##..####.#.#.##.##.#....####.####....#.#..###.##.##....#####..#.##.#.# +#........#.##.#...#.##.....#.###.#..##.##..#..##..#.....###.#.#.#.##.###..#.#.....#..#.#.#.###.#.### +####.#.#####......#.##..#.####.#.....##.######..#..#..#.##..#.#.#..#..####...#.#...#.##.......#....# +##.#.##..#..####.#.#..#..#.##...#.#.#.#...#.#.#.#.#..#.....###.#...#.....#...###....###.##..#.#.#..# +.####.....#...##..##.####.#.#.###......##.###...#..#..###.##..##.##...##...###.....#..##.##.#.###... diff --git a/Advent-of-Code-2021/AOC-20/main.c b/Advent-of-Code-2021/AOC-20/main.c new file mode 100644 index 0000000..1dbcdc9 --- /dev/null +++ b/Advent-of-Code-2021/AOC-20/main.c @@ -0,0 +1,144 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#if 0 +#define PART_1 +#else +#define PART_2 +#endif + +#if 0 + #define FILE_PATH "example.txt" + #define T_WIDTH 5 + #define T_HEIGHT 5 +#else + #define FILE_PATH "input.txt" + #define T_WIDTH 100 + #define T_HEIGHT 100 +#endif + +#define WIDTH 256 +#define HEIGHT 256 + +#define OFFSET_X ((WIDTH/2) - (T_WIDTH/2)) +#define OFFSET_Y ((HEIGHT/2) - (T_HEIGHT/2)) + + +int board[WIDTH][HEIGHT]; +int new_board[WIDTH][HEIGHT]; +int enchance_alg[512]; + +void parse() +{ + FILE *fp = fopen(FILE_PATH, "r"); + if(!fp) { + fprintf(stderr, "ERROR: Could not open file: %s\n", FILE_PATH); + exit(EXIT_FAILURE); + } + + char line[1024] = {0}; + + fgets(line, sizeof(line), fp); + for(int i = 0; i < 512; i++) + if(line[i] == '.') + enchance_alg[i] = 0; + else + enchance_alg[i] = 1; + + fgets(line, sizeof(line), fp); + + char ch; + int i = 0; + while((ch = getc(fp)) != EOF) + { + if(ch == '\n') continue; + else if(ch == '.') + board[i%T_WIDTH + OFFSET_X][i/T_WIDTH + OFFSET_Y] = 0; + else if(ch == '#') + board[i%T_WIDTH + OFFSET_X][i/T_WIDTH + OFFSET_Y] = 1; + + i++; + } + + + fclose(fp); +} + +int generate_index(int *vals) +{ + int index = 0; + for(int i = 0; i < 9; i++) + { + index |= (vals[8-i] & 1)<< i; + } + return index; +} + +void enchance() +{ + for(int i = 0; i < HEIGHT; i++) + { + for(int j = 0; j < WIDTH; j++) + { + int vals[9]; + for(int y = -1; y <= 1; y++) + for(int x = -1; x <= 1; x++) + { + int vals_i = (y+1) * 3 + (x+1); + if(i+y < 0 || i+y >= HEIGHT || + j+x < 0 || j+x >= WIDTH) + vals[vals_i] = board[j][i]; + else + vals[vals_i] = board[j+x][i+y]; + } + new_board[j][i] = enchance_alg[generate_index(vals)]; + } + } + memcpy(board, new_board, sizeof(board)); +} + +void print_board() +{ + for(int i = 0; i < HEIGHT; i++) + { + for(int j = 0; j < WIDTH; j++) + if(board[j][i] == 0) putc('.', stdout); + else putc('#', stdout); + + putc('\n', stdout); + } +} + +void print_alg() +{ + for(int i = 0; i < 512; i++) + { + if(enchance_alg[i] == 0) putc('.', stdout); + else putc('#', stdout); + } + putc('\n', stdout); +} + + +int main(void) +{ + parse(); + +#ifdef PART_1 + for(int i = 0; i < 2; i++) +#endif +#ifdef PART_2 + for(int i = 0; i < 50; i++) +#endif + enchance(); + + int lit = 0; + for(int i = 0; i < HEIGHT; i++) + for(int j = 0; j < WIDTH; j++) + if(board[j][i] == 1) lit++; + + printf("%d pixels are lit\n", lit); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-3-old/input.txt b/Advent-of-Code-2021/AOC-3-old/input.txt new file mode 100644 index 0000000..e324b50 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3-old/input.txt @@ -0,0 +1,1000 @@ +011110111110 +110111000111 +001000001010 +000101111101 +101011011110 +010010010111 +111101001100 +111101011100 +110011101101 +001111010011 +110000000110 +111000010001 +011011011000 +000111110100 +111100101010 +001011001100 +011100000101 +100011110110 +111001011101 +110101011010 +110101101111 +011011101001 +111001010110 +011000101000 +100101111100 +011101110010 +010000110000 +111010110100 +000001000011 +110111000000 +101010010110 +100000001011 +001111110001 +001111000011 +001101001010 +100011001111 +001011001101 +010001010000 +000000000000 +011001011011 +000101100101 +010101101101 +000110011001 +100100110001 +010110011011 +110101100101 +010101101011 +011100000000 +011001101000 +001000100110 +101001010011 +111111101101 +100010111001 +000011011100 +010001111100 +011011111100 +000100010001 +101111100110 +000000111101 +111010110001 +000100110101 +111010100100 +111111001011 +001000010010 +100100000110 +010111010110 +111111010110 +000011011011 +001111001000 +000000010101 +011011100111 +110010111110 +110001011111 +011101100110 +010011111100 +010101100011 +000110010110 +100110001111 +010111100000 +001110110000 +101010010010 +010011011001 +100000100110 +010100011010 +100110001010 +111110001001 +101001000000 +100010110000 +101100001000 +000000110101 +100001010011 +011101100001 +000100111001 +011110100001 +001111000111 +001011001111 +110111000101 +011001010101 +101100111000 +011111110010 +000000100001 +100101011111 +110110011100 +011001011101 +000101010001 +100100001000 +110100001111 +101100010010 +010000011001 +010111011111 +001001101101 +101110101001 +101111011101 +100011010010 +101001100010 +110010111101 +100100010001 +100010011000 +100010110110 +100110101101 +101110010011 +111111011001 +100110100111 +011111011100 +011011001010 +101000011110 +010110011110 +101000111010 +110100001101 +111011010001 +011111100010 +101111000010 +111011111011 +001000011010 +010000001101 +001101110101 +000110010011 +011001110110 +110010010001 +010001010011 +110111100100 +011100110011 +011000010111 +100011101110 +101100110110 +101000100111 +100000000111 +011011011010 +011111011000 +010001111101 +000010111100 +101100100001 +011011111111 +010111001110 +110100111101 +011101111010 +100010001001 +101110011111 +000000000101 +110100100000 +010100011100 +101100111011 +110011110101 +000101110111 +001111100011 +001110001001 +101001001111 +010000011101 +100101111101 +001101000111 +000100100110 +010110111110 +111110110011 +101010101011 +101010011011 +100011010101 +101110010100 +110110001100 +111001010010 +011000111000 +110011001101 +111100100000 +100111110011 +110011010000 +100000101111 +110110101001 +001010000010 +000010100100 +101111101001 +011111001001 +111001111011 +001100001110 +111011011101 +110101001111 +010100001101 +000000001111 +001111001111 +100101101001 +011101101101 +101100101100 +110100101001 +100111001001 +111111001001 +101011000011 +010101110000 +010110100100 +101011000100 +100010001111 +111001101010 +111010010010 +000011000100 +110000111101 +110011110111 +101111011000 +100110110110 +000011111010 +011011110111 +011010010001 +110010111000 +100101000101 +110111011101 +110010011110 +010101010100 +110010011000 +101001101100 +100111011101 +001001100101 +011001010001 +001101000000 +011110111010 +001010011001 +011010101101 +101001001010 +001101101010 +100110111011 +000000101111 +111100000110 +100000100000 +011100010101 +111000110010 +111010001010 +111000011010 +000111001101 +001111000000 +011110000111 +101001010110 +011001001010 +001010001001 +111001001101 +111111000001 +001001111110 +101000111110 +001111010110 +010000011111 +010101010001 +011001010010 +111010000011 +110000111100 +110101000000 +000111011110 +101100101011 +001110101011 +000110100111 +010100000001 +101111000001 +000110101100 +111110010000 +010000110101 +000010000010 +111111111101 +011101001010 +001111100101 +100101010111 +100011010100 +110111110010 +100110110011 +011100101011 +000001010011 +010110101001 +000111110101 +101111001001 +100010101110 +111010010011 +100101000111 +111101110110 +100101110011 +001000110000 +010111100001 +100100011100 +000100111011 +101110111111 +100110010001 +100100111000 +011010111010 +111011101101 +110010110100 +101110101110 +110001101101 +110000011011 +101000000010 +010100000111 +000110100101 +011000101100 +111001111110 +101010100001 +101111111001 +100010010100 +111001111000 +100000011010 +111000101110 +010000000101 +111111000111 +100001011110 +100110111001 +101100101001 +000011111101 +111101110001 +101010010011 +101000110111 +000000111111 +110001000111 +010110000010 +011010101011 +000100110000 +101010111101 +000100101101 +001000001100 +010000000111 +100100100011 +010010111101 +000011001010 +010100111110 +011110110101 +110001000110 +010001100011 +100111010100 +100000101010 +110101110001 +111010000111 +011000000011 +001101011000 +100110101110 +101110101010 +001101101001 +111011101111 +011010001110 +111100001100 +111111001000 +111000110100 +111101100011 +010010101011 +111101100101 +111111000011 +110100000011 +110000010101 +001111111000 +100100101111 +100101111000 +011111110001 +000110001000 +001101110110 +110010011010 +110010101110 +011010011010 +000011000101 +101101100000 +100111111000 +001100000010 +101101101010 +100100111001 +111100101100 +101100110010 +010010111110 +101001100101 +100001111001 +100010000101 +110111010011 +100000010011 +111100000011 +110000000010 +101101001100 +011001001000 +101011110001 +011111011010 +110001010111 +110001101100 +011001000011 +111101000011 +110100100110 +010111111001 +011011111101 +100100110011 +011111000100 +100010011110 +000010011011 +111101100111 +111001111010 +001111111100 +111011001111 +111011110100 +000001101111 +110010110110 +101000101101 +111000011100 +001001101010 +010110100001 +000101110110 +110101101101 +000001001010 +001011010011 +010011001001 +100101111010 +000100011011 +000100010010 +101110110001 +100000011001 +011000010000 +101111001010 +101111100111 +001000000110 +100110011100 +001010101011 +111001001100 +101110101011 +100100011001 +010011101001 +110000001100 +101010100000 +011101010010 +001010001110 +001111101110 +101101011100 +011000100001 +111100011101 +010011110000 +111010001011 +011101000111 +001100000100 +101110010110 +111101010111 +011010100001 +011110000101 +011100001100 +100100010011 +000100110111 +100101111110 +010100011011 +111110100000 +011010011111 +011100010011 +010111101000 +000000010111 +100001110001 +111100011100 +001010110100 +100111000000 +001110101000 +011010000001 +110101110110 +010010110101 +011110100000 +010101001001 +011111111100 +011100110010 +100101011010 +011011000101 +101000110011 +000000100101 +110111101001 +010101100110 +101101111011 +011100100110 +101110011101 +010000001001 +000010100111 +000000110110 +101111101110 +111100010011 +001110101001 +000000011000 +110011100011 +100001101010 +010010101111 +110111100011 +011001110001 +101000100001 +011111001101 +110101011101 +000010110100 +101110101111 +111011000111 +101101001001 +100110000111 +001110110100 +001001100010 +010110001001 +100010001010 +111100000101 +101111101000 +100001100110 +111001010001 +110101111100 +000010100011 +010001010010 +011111101110 +101110011010 +110111101011 +110101000110 +101001111000 +000110010010 +110010011100 +101101010100 +000011001100 +010100100000 +001010001111 +100111111110 +100111011001 +001011100010 +101010101110 +011011001111 +010011111001 +101101000110 +100001111011 +000100001000 +111111010100 +111001111101 +001100101100 +000010111000 +000110110011 +011101110011 +111100000001 +100000100101 +100011001110 +101000101100 +101010010000 +110110110000 +010101011010 +001101100101 +010010101010 +111000100100 +110000001101 +100001000000 +010000100011 +110001010001 +010010111001 +011100000110 +100111100010 +110110110110 +100001000001 +100010101010 +001111100110 +101101101110 +110010010111 +111100101011 +101011110010 +111001011110 +010101000010 +101011001010 +001111110111 +111100100101 +111001110010 +010110001101 +110000110100 +110010110000 +101110101101 +001010000001 +101111000101 +001110100001 +010011101111 +001100000111 +101100110001 +110011111011 +011110001010 +010111111101 +000001111011 +000001001001 +001101000100 +111110011011 +010000011011 +110011000110 +001010000111 +111100011110 +000110111010 +001011101110 +001010000101 +011101010111 +110000101111 +010010010011 +110100110110 +100011000011 +001111100001 +000110000000 +000110111110 +011001100001 +010111111010 +010101010111 +000010011000 +010011000010 +100000011100 +000111101101 +001001010000 +111000000011 +010110001010 +101000001000 +010000001000 +011001101110 +110001110110 +100010011011 +011011001000 +001100101111 +011010111100 +010100110011 +000111000011 +111101010011 +000111011011 +011110000110 +101100000001 +011111100000 +111010101110 +110001101010 +100101000100 +101011101001 +110010101111 +010010011011 +100110111101 +010000111010 +010100011000 +110111010101 +001000011100 +010011000110 +101010001000 +110010100011 +001101011010 +000011110000 +100101001101 +011001011111 +100011100111 +100001101000 +001100011100 +110001010000 +101001110111 +000001110010 +010011100111 +110011110011 +101110111100 +010110010101 +101101101101 +011001000010 +001110010010 +111111001101 +010000100111 +111101110011 +011101101000 +000111101100 +110101011100 +101001101101 +101001100011 +001101111011 +000111111001 +010000000010 +100011110000 +111111011110 +011000110010 +110001110010 +010010100110 +100000111101 +010001001110 +110001111111 +110111000100 +111010011100 +001100101001 +111001111100 +001100101010 +000000010010 +010111101011 +101100001111 +110101001100 +100101110010 +011101111110 +111100101110 +010010000100 +111010100010 +001000101011 +001000110111 +100011001001 +111101111010 +110101010111 +001101100010 +000110011100 +010111101111 +111110000010 +000100101011 +010000100110 +111000010100 +111110011111 +010001001100 +000000001000 +011001110101 +101110100000 +011100100001 +110001100101 +111101011001 +101000101001 +000011010100 +001000001111 +100101110100 +001101110011 +001000100111 +101011011100 +000100000010 +001111011001 +001001110101 +001101011110 +001111011010 +001111001011 +100010100011 +000000010011 +100100010100 +111001000011 +110110111110 +001110011101 +011011010111 +011100001111 +101110100101 +111101010110 +111100100111 +101111101100 +111000000001 +101011011101 +101011010101 +100111000001 +111100110001 +111111100001 +110001110101 +011010111011 +011100101000 +111101011010 +101010010100 +111001011011 +000100100010 +111110000111 +110110001000 +011100111001 +100100100100 +010000100010 +111010001000 +010001011010 +100010111110 +001001001111 +100001101101 +000001111000 +001100110110 +000101101010 +011000001001 +111011101010 +100110001101 +110001010011 +001000000111 +110111001101 +111010110111 +100010101101 +100101101011 +001111100010 +111011101001 +000001110001 +011110001000 +001111100100 +001001010010 +110011100001 +110011100100 +111110111110 +111011011001 +111111111011 +110011000111 +011111000110 +110001011101 +010101111000 +111100101101 +010001101001 +110001101001 +111101000010 +101110000111 +000011101101 +001110000010 +011110011101 +100011001101 +100010111011 +010001101011 +011101110110 +000010011001 +100100010101 +011100101101 +010010100010 +101110100011 +100001111110 +001011000000 +000000000010 +111000111110 +100010010101 +111101100010 +100101000110 +111001100100 +101111001111 +101110110111 +010001000100 +101101110010 +111001101101 +111101101111 +000100000100 +101011011011 +111000110001 +101010100101 +110100000001 +000111010110 +001000010100 +111110010111 +011101000110 +100111110010 +010010000011 +101011100100 +101000100110 +110101100001 +001110000000 +111101100100 +011101010011 +111100101000 +100000010101 +010011010011 +011000001100 +011111001111 +110100001011 +100000001111 +001011001010 +010001110110 +101000110001 +110001000101 +010100111001 +100000010010 +101010111100 +001110011001 +110000100011 +010010000111 +101111110000 +010101010010 +011010001001 +111010011111 +000101100010 +000101110011 +100011111100 +000100000111 +101101100011 +000101111010 +000011010001 +111000011101 +100110000110 +110100100011 +010111000010 +100011001011 +010011100000 +010111100101 +100011100000 +011000010010 +010111010010 +011010010110 +111001111001 +101100011100 +110111111000 +001001011000 +000000011100 +011000011010 +011110000001 +110110000100 +010010100111 +100000100111 +011111110110 +001010110000 +110011000011 +001010110011 +011110101011 +101011111001 +010101011000 +001100101011 +000111100011 +110010001111 +001011101000 +010101011111 +001101000010 +010011101000 +111111110110 +101011111111 +110000001010 +011011100110 +110001111000 +100001110000 +100011000101 +111001000101 +101101101000 +010000011110 +100100111110 +101010110010 +000000101101 +011100111011 +101110101000 +000011000001 +100010110010 +000101101101 +110110100001 +001001011111 +101111110010 +010011110101 +101000110100 +000001101000 +111110000000 +011000111100 +010010010010 +011110001111 +110100111000 +010011100011 +000100100100 +010000110001 +000000001011 +011110111000 +010000000011 +110010010100 +111110111001 +011111111001 +010000101000 +110101100011 +100110001001 +011011000111 +100110101010 +011011011111 +011001011001 +110110100101 +011101000010 +001000100100 +000100110100 +110000111010 +000100100101 +100000111110 +010110110101 +110100100001 +110101100111 +101000100000 +101110001001 +011000111110 +110010101010 +011100110000 +001101000011 +110101101110 +111000001010 +110101000001 +100111101001 +011010111001 +010011110011 +101000011011 +111001010111 +010000000001 +100111001010 +010101100111 +011100101100 +101011110111 +100111100110 +100111100000 +110010111100 +100011010011 +110011110000 +111100010010 +001000101010 +101110110110 +010111101101 +011110010000 +000101000101 +111110111000 +111010100001 +011101011101 +111110000011 +010011101010 +010111000111 +100010011001 +000010000000 +000000100100 +110110110101 +100010100100 +101000000101 +111111100000 +101101101111 +010100101110 +111111100101 +101000010101 +001011111000 +001110110011 +010101100000 +001010101010 +111001100101 +100110000011 +010101011011 +101001110100 +100011100001 +100110101000 diff --git a/Advent-of-Code-2021/AOC-3-old/main.c b/Advent-of-Code-2021/AOC-3-old/main.c new file mode 100644 index 0000000..51cab24 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3-old/main.c @@ -0,0 +1,86 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <stdint.h> + +#define N 5 +#define INP_COUNT 12 + +int table[N]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk what fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') { i = 0; continue; } + + if(ch == '1') + table[i] += 1; + + i += 1; + } + + fclose(fp); +} + +void PrintTable() +{ + for(int i=0; i<N; i++) + { + printf("bitplace %d: %d\n", i+1, table[i]); + } +} + +int PartOne() +{ + int gamma_val = 0; + for(int i=0; i<N; i++) + { + assert(table[i] != (INP_COUNT/2)); + + if(table[i] > (INP_COUNT/2)) + { + gamma_val = gamma_val | (1 << (N-1-i)); + } + } + + int epsilon_val = gamma_val; + for(int i=0; i<N; i++) + { + epsilon_val = epsilon_val ^ (1 << i); + } + + int result = gamma_val * epsilon_val; + return result; +} + +int PartTwo() +{ + + + int result = 0; + return result; +} + +int main(void) +{ + memset(table, 0, sizeof(int)*N); + ParseInput("sample.txt"); + + PrintTable(); + printf("Part 1-RESULT: %d\n", PartOne()); + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-3/sample.txt b/Advent-of-Code-2021/AOC-3-old/sample.txt index a6366a8..a6366a8 100644 --- a/Advent-of-Code-2021/AOC-3/sample.txt +++ b/Advent-of-Code-2021/AOC-3-old/sample.txt diff --git a/Advent-of-Code-2021/AOC-3/build.sh b/Advent-of-Code-2021/AOC-3/build.sh new file mode 100755 index 0000000..6be9241 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +gcc -o main -Wall -Wextra main.c + +./main diff --git a/Advent-of-Code-2021/AOC-3/example.txt b/Advent-of-Code-2021/AOC-3/example.txt new file mode 100644 index 0000000..a6366a8 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/example.txt @@ -0,0 +1,12 @@ +00100 +11110 +10110 +10111 +10101 +01111 +00111 +11100 +10000 +11001 +00010 +01010 diff --git a/Advent-of-Code-2021/AOC-3/main.c b/Advent-of-Code-2021/AOC-3/main.c index 51cab24..29d334e 100644 --- a/Advent-of-Code-2021/AOC-3/main.c +++ b/Advent-of-Code-2021/AOC-3/main.c @@ -1,86 +1,97 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <assert.h> -#include <stdint.h> -#define N 5 -#define INP_COUNT 12 +#if 1 + #define PART_1 +#else + #define PART_2 +#endif -int table[N]; +#if 0 + #define FILE_PATH "example.txt" + #define NUMS 12 + #define BITS 5 +#else + #define FILE_PATH "input.txt" + #define NUMS 1000 + #define BITS 12 +#endif -void ParseInput(char *filepath) +int nums[NUMS] = {0}; + +void parse() { - char ch; - FILE *fp; - fp = fopen(filepath, "r"); + FILE *fp = fopen(FILE_PATH, "r"); + if(!fp) { + fprintf(stderr, "ERROR: Could not open file %s\n", FILE_PATH); + exit(EXIT_FAILURE); + } - if(fp == NULL) - { - fprintf(stderr, "ERROR: something with file idk what fuck you"); - exit(EXIT_FAILURE); - } + char line[32]; + int index = 0; + while(fgets(line, sizeof(line), fp) != NULL) + { + for(int i = 0; i < BITS; i++) + nums[index] |= (line[i] - '0') << (BITS-1 - i); + + index++; + } - int i = 0; - while((ch = fgetc(fp)) != EOF) - { - if(ch == '\n') { i = 0; continue; } + fclose(fp); +} - if(ch == '1') - table[i] += 1; +ulong gen_gamma() +{ + int most_common[BITS] = {0}; + + for(int i = 0; i < BITS; i++) + { + int ones = 0; - i += 1; - } + for(int j = 0; j < NUMS; j++) + if(nums[j] & (1 << i)) ones++; - fclose(fp); + if(ones > NUMS/2) most_common[i] = 1; + } + + ulong gamma = 0; + + for(int i = 0; i < BITS; i++) + gamma |= most_common[i] << i; + + return gamma; } -void PrintTable() +void print_nums() { - for(int i=0; i<N; i++) - { - printf("bitplace %d: %d\n", i+1, table[i]); - } + for(int i = 0; i < NUMS; i++) + printf("%b\n", nums[i]); } -int PartOne() +void part_1() { - int gamma_val = 0; - for(int i=0; i<N; i++) - { - assert(table[i] != (INP_COUNT/2)); - - if(table[i] > (INP_COUNT/2)) - { - gamma_val = gamma_val | (1 << (N-1-i)); - } - } - - int epsilon_val = gamma_val; - for(int i=0; i<N; i++) - { - epsilon_val = epsilon_val ^ (1 << i); - } + ulong gamma = gen_gamma(); + ulong epsilon = (~gamma & ~(~0 << BITS)); - int result = gamma_val * epsilon_val; - return result; + printf("Power consumption is %lu", gamma*epsilon); } -int PartTwo() +void part_2() { - - - int result = 0; - return result; + exit(EXIT_FAILURE); } int main(void) { - memset(table, 0, sizeof(int)*N); - ParseInput("sample.txt"); + parse(); + +#ifdef PART_1 + part_1(); +#endif +#ifdef PART_2 + part_2(); +#endif - PrintTable(); - printf("Part 1-RESULT: %d\n", PartOne()); - - return 0; + return 0; } diff --git a/Advent-of-Code-2021/AOC-5/main.c b/Advent-of-Code-2021/AOC-5/main.c index ea39e06..d83ec06 100644 --- a/Advent-of-Code-2021/AOC-5/main.c +++ b/Advent-of-Code-2021/AOC-5/main.c @@ -97,42 +97,16 @@ void print_board() } } -void part_1() +int main(void) { parse(); int count = 0; for(int i = 0; i < HEIGHT; i++) for(int j = 0; j < WIDTH; j++) - if(board[j][i] >= 2) count++; + if(board[j][i] >= 2) count += 1; printf("Count is %d\n", count); -} - -void part_2() -{ - parse(); - - int count = 0; - for(int i = 0; i < HEIGHT; i++) - for(int j = 0; j < WIDTH; j++) - if(board[j][i] >= 2) count++; - - // print_board(); - - printf("Count is %d\n", count); -} - -int main(void) -{ - -#ifdef PART_1 - part_1(); -#endif - -#ifdef PART_2 - part_2(); -#endif return 0; } |