From 79a612352643c5cf0c947f934e03d319f7e97f17 Mon Sep 17 00:00:00 2001 From: David Vereb Date: Thu, 1 Dec 2022 09:14:56 -0500 Subject: [PATCH] 2022 begins. --- .gitignore | 3 +- 2021/14/data | 102 ++ 2021/14/example_data | 18 + 2021/14/main.py | 45 + 2021/14/main2.py | 45 + 2021/15/data | 100 ++ 2021/15/example_data | 10 + 2021/15/main.py | 12 + 2022/1/data.txt | 2238 ++++++++++++++++++++++++++++++++++++++++++ 2022/1/main.cpp | 57 ++ 2022/1/main.rs | 38 + 11 files changed, 2667 insertions(+), 1 deletion(-) create mode 100644 2021/14/data create mode 100644 2021/14/example_data create mode 100644 2021/14/main.py create mode 100644 2021/14/main2.py create mode 100644 2021/15/data create mode 100644 2021/15/example_data create mode 100644 2021/15/main.py create mode 100644 2022/1/data.txt create mode 100644 2022/1/main.cpp create mode 100644 2022/1/main.rs diff --git a/.gitignore b/.gitignore index 5236e1e..14e091d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ - +*a.out +*main diff --git a/2021/14/data b/2021/14/data new file mode 100644 index 0000000..9c69fce --- /dev/null +++ b/2021/14/data @@ -0,0 +1,102 @@ +ONHOOSCKBSVHBNKFKSBK + +HO -> B +KB -> O +PV -> B +BV -> C +HK -> N +FK -> H +NV -> C +PF -> K +FV -> B +NH -> P +CO -> N +HV -> P +OH -> H +BC -> H +SP -> C +OK -> F +KH -> N +HB -> V +FP -> N +KP -> O +FB -> O +FH -> F +CN -> K +BP -> P +SF -> O +CK -> K +KN -> O +VK -> C +HP -> N +KK -> V +KO -> C +OO -> P +BH -> B +OC -> O +HC -> V +HS -> O +SH -> V +SO -> C +FS -> N +CH -> O +PC -> O +FC -> S +VO -> H +NS -> H +PH -> C +SS -> F +BN -> B +BF -> F +NC -> F +CS -> F +NN -> O +FF -> P +OF -> H +NF -> O +SC -> F +KC -> F +CP -> H +CF -> K +BS -> S +HN -> K +CB -> P +PB -> V +VP -> C +OS -> C +FN -> B +NB -> V +BB -> C +BK -> V +VF -> V +VC -> O +NO -> K +KF -> P +FO -> C +OB -> K +ON -> S +BO -> V +KV -> H +CC -> O +HF -> N +VS -> S +PN -> P +SK -> F +PO -> V +HH -> F +VV -> N +VH -> N +SV -> S +CV -> B +KS -> K +PS -> V +OV -> S +SB -> V +NP -> K +SN -> C +NK -> O +PK -> F +VN -> P +PP -> K +VB -> C +OP -> P diff --git a/2021/14/example_data b/2021/14/example_data new file mode 100644 index 0000000..6c1c3a1 --- /dev/null +++ b/2021/14/example_data @@ -0,0 +1,18 @@ +NNCB + +CH -> B +HH -> N +CB -> H +NH -> C +HB -> C +HC -> B +HN -> C +NN -> C +BH -> H +NC -> B +NB -> B +BN -> B +BB -> N +BC -> B +CC -> N +CN -> C \ No newline at end of file diff --git a/2021/14/main.py b/2021/14/main.py new file mode 100644 index 0000000..34a063b --- /dev/null +++ b/2021/14/main.py @@ -0,0 +1,45 @@ +str = '' +data = {} +letters = [] +with open('data', 'r') as fp: + for line in fp: + if(' -> ' in line): + pair = line.strip().split(' -> ') + data[pair[0]] = pair[1] + elif(len(line) > 1): + str = line.strip() + +for ch in str: + if(not ch in letters): + letters.append(ch) +letters.sort() + +# # DEBUG(dev): +# print(data) +# print(str) +# print(letters) + +for step in range(0, 40): + print('BEFORE:', str) + new_str = '' + for i in range(0, len(str) - 1): + lookup = str[i:i+2] + print(lookup) + if(lookup in data.keys()): + new_str += str[i] + data[lookup] + else: + new_str += str[i] + new_str += str[-1] + str = new_str + +counts = {} +for ch in str: + if(ch in counts): + counts[ch] += 1 + else: + counts[ch] = 1 + +counts_list = list(counts.values()) +counts_list.sort() + +print(counts_list[-1] - counts_list[0]) diff --git a/2021/14/main2.py b/2021/14/main2.py new file mode 100644 index 0000000..d29517c --- /dev/null +++ b/2021/14/main2.py @@ -0,0 +1,45 @@ +str = '' +data = {} +letters = [] +with open('data', 'r') as fp: + for line in fp: + if(' -> ' in line): + pair = line.strip().split(' -> ') + data[pair[0]] = pair[1] + elif(len(line) > 1): + str = line.strip() + +for ch in str: + if(not ch in letters): + letters.append(ch) +letters.sort() + +# # DEBUG(dev): +# print(data) +# print(str) +# print(letters) + +for step in range(0, 40): + new_str = '' + for i in range(0, len(str) - 1): + lookup = str[i:i+2] + if(lookup in data.keys()): + new_str += str[i] + data[lookup] + else: + new_str += str[i] + new_str += str[-1] + str = new_str + print('Step ', step+1, ', length', len(str)) + + # NOTE(dev): un-indent this (take it out of the for loop) for just a final answer + counts = {} + for ch in str: + if(ch in counts): + counts[ch] += 1 + else: + counts[ch] = 1 + + counts_list = list(counts.values()) + counts_list.sort() + + print(counts_list, counts_list[-1] - counts_list[0]) diff --git a/2021/15/data b/2021/15/data new file mode 100644 index 0000000..ef64dc1 --- /dev/null +++ b/2021/15/data @@ -0,0 +1,100 @@ +9165985876154699219988192797299938946759548993842382179897895847959995468789384779887969965834298757 +9998264799399739852669159899969915752881369928979589425659869512849898348591988899941938989958981368 +8899439372928798295981284899995498957198997822776999766989269673341115866632499916582179985999797178 +9421373314798816327241583824298987799745811978869899899899999689988933652499891999899718759652641398 +9949959989598519929632977671926983547787167773939739198988988851889519228348573848979828599971727943 +2989192448779756984992587956689999842746119939998567894718899918799954281648927282191699499764931166 +9536499426969676189784443598979559899499773119978188394689557995599331996979736693529419681251956996 +1751936936954979779895998917863998697858138691879749999727789764741997539275579593798975539798818972 +7274746616894977772987689459988988891794769772199789185982726479992789563994126143759648659653627929 +9768211178649269995923493912176968666679999859829913848396992289798892197419967914777851877899477278 +9548265381888989898295865115497574817515178999881998168798969539989897979118423366393898169329939816 +5346816194398971492996938739782725986596757996472498951666679779287752997484725936582558299359964812 +2169889968977588483272986596967998729999883958728879796999737989942928997399898577324799379798165679 +5756791285489939716695977945746649394898965799971791856215827997699758829299499895496993375817688889 +1189911823962199612255959754716953775367595418858921381973577497988994381699599376948136788285998274 +6979939299876267486998569159464199464965974658469723835541132825855912999935783995325776519991867869 +7829881839997878488734339898145124968389716637926975397882799631985728918519668146942356911683694975 +4973997156985297758563699888285794535932928974966978296562139199889893476728999942416259889912711471 +9534797994999788999759474799734844192166842694971197691854895641895188586895455192589986798997913693 +2819784988295365719599997589858664998979399989735399884134499895873389479651295996498866989999839974 +6129944129969453989699888866976269999128469799982997963676678293639494188967181417362922546475281598 +9716591619494494558731969871917781639763288288691962634219628479989988828962651246459129568974491171 +7894482759988943587818779691955666934841799931371572868778856815865991124376396974593984947897442991 +1858394839149329949299818139987736884848178995897668499996188998667699618978779495959989927996996397 +9917119977481935978699197129381282957978683881779735689583195993458959989897975199999285945815997999 +1699128644295779552889817864638995225998895287579281281998594696644213479297199692979781937997179875 +8289472999575769888986161678994171392789714988719932799199558696689379278929798887977551878788398787 +9175199787918919864185866129967892999898318993291829953849829788999738939999469848949591989149962712 +6199185639948988878676462732119197225882925435874993975768952939825978994996892549999699984912695356 +3396488583898545189449831859997919671368765298895692847986994925119921865818912189499168979958896494 +9938398336984195997576689194134985999635325783571526493894394589917988793989755746999698829649589393 +6985999497989855798918845568728129349777627978979362788359497952698956998292996918648692699694349887 +1983998898992942689898989791697792913121476987631657959299998868769559979688918876893688862439185197 +7357776772998794811999929459919571597899775797198394831478974157594549666253368399586349899987699999 +7959339994696971922632949191545959757987989979787788169979748972545188912811999284691666989915589771 +9759961834557989443271499976572889278289319995879484972649589489199519573998999779383692242897767588 +9179641759649515678926897874488858988897787895855979191899776967749898123692484838554413919817918963 +6839761379993114699928685489349481791394595895995488717149328139993956495742445794747189959976877649 +7719888678899926948979191678165949542927483596385943836398298659699148778343914768999898197267997991 +8769727958885176392169934146934172488871783986753744485932511888999799159194751538987186924419884479 +8991999992999929999897984599767977994699827768813861298818993288386943869782797583698682188885283399 +7618891897968939798498999399278379698962758659288163913969875574557443483997692961986999939899819481 +8879168556577788339549879912587944289995777798881688244889799389891799876819699576957557971877898128 +9291695492736749179768777989972456198819896897386591181956469899994155718299785968686938589318979479 +7795999789358882518386787487224292238877893956695912892699678996798249199324897986249725799479399977 +7157587585956489829119899759896997988918879818491999931184192141949199172799356679472486896195864474 +8369998998796539973399979987949986863639829688617494995142799799778639869918868177475771699198897648 +6597979998999646797717999135983617949772192975367951599248888799957499785994774771558359664883693989 +8494399497884369731998936499887638658943929616778716995355827188745777858983426799559721799739362629 +7988688889359569698815957687229757873596999199938929146584679599188685439814466838789683219554419476 +9247298485768968989794782295879689497761879956994316114992795924987262939579993889586584967699911179 +9585318399982677997578979671589977319169586337196999959189521499887711992343851295981988819951696391 +9688419987598317988779256198579659993398274893319912676925791429994831998147985462785322692958417991 +9162526572947889939619891135679859992512868978725888837198497899147199825914711544192984934699878858 +9997992172487298739215471619688889939819838188921969391991648949979166298795194179866892977317488668 +4342969513889787361777751972798659462495119377122327857968869995779944989446988786669168689799978198 +9991989792887933999782849992885388199539897175961949179928388186994694998865752811971681796835228899 +9689884899572994167989994913659819996941825788877898819911788969419991277989227389959829597962878797 +9919879157714445923163829999735888889724892834556637899899999974386932299127993655996239789769999544 +8158429263197997788393974998999939783878693949897825898975995959979986635699272784592895953298769979 +6933156399191389719992767671896649494989689977121886269912939799779176467784638649979932992778611947 +9937886748328953482685979758934658999819989845699372899934596991259755741819979779889881397565568579 +6628287411551868899648999511774894539834357749799788481594933187788979179772699757813897655969637759 +1681758889993977881987844998586378799289969999542735618971489988849699628668119898999679199493949189 +7756952966791755589777886975949697297729368719914568929921989979278297994486928996985666791996513546 +7959939142776881868999785876799728991368773296952962918971941199687791336941297836969992566198117899 +9919799591383641992451999795686291882995991159937526287799259396499782592953878378919512331399769295 +9979988697799299993248298599458499952548969526718987894849849961566959196296836979299696595499951269 +8989115299788834687596939899183482448889849883899881337161943668283395379982966119363885868799817686 +3917979748934696925996487991958936699899582264499928897937594999993391587881813378359971812919779972 +7798825938413749319999785941489868587674397449269738978317389938919984622199581498529938819682972471 +7749948181969657924978787838596695869966969369158962427829991499668977295896254897998989743989952389 +6398998955793159938819887788968371888968395499298999755899949268632898528951445886293997299392969779 +9539983773686993498991392899889572558299175987819981797981886747694169489893727157979378595839496298 +9599999287193787789729986389617989992374479972959749982818939999895692869845931449861767839389829149 +4889176836968695418797941267779399488818276299865898498649489796971967884999112828966259271689857259 +7139139187955994831738585298962698949981181887589699969919418116293969946431635243579918986885919619 +7935837589876972417397869798312741789988882795986987744696696629647813993997762979599189148298958581 +8791284382878199766798982957837371997961791491996313339915819373928948979938596612197699691473969914 +1372974376943738718696489825854989786382983999879965536283589995655483569334269859559761199879679291 +9719671746885959293824693968698399315424948599622489865269469961617669916732853892695261177787994496 +7849319899791243818799879975258532467699699999398269787199341236894749619399991856788917729181194197 +9148263323757681139949799197198549259446781912979561927929891898923997238737858757915394778591127667 +1945591989843987198391756487965892217958111951642219915715439797998675786222936815998966826782589594 +5254778838276178988551266998775337643868756772978159294191819424888551874271745598136847865594999289 +3998557499888479397893111869792537426834985941959185929798919875628859952429849886849639853349182496 +8958877677623879221669563361998988956937492798913659491897715599879989983979859984661929198589817564 +9989969281947994946512996153988898382127889834868897498898867797998892148557494839482788798269898496 +9779851919689459958899912662756981619298821434879339749956713988385759469959788279765789991925947918 +4196471827218751217999955385399979199189581896987488518319752529829892282899638773984698854832217793 +5968399569814182278918739959691249997958587277596698779311494824187981838837892479347738267879912541 +8659894118598996577145167494795592898597175979829589886499183913197276893979278479678988218798894991 +6649277899864442637895792699719172999998662937819979979769821897696686788719291967114346689819212978 +6699889979874997773889958977455779952988466968759738452847569993821963796198741514377779188577811889 +1173976886399735895884999486498511998399588328832288555979166889776686858695414825689877994898917949 +9629147139882191719857926675389957799296279989442991999622669639755767892922474778888299984452999898 +4391879947595258989144156986799899833458894496218777872997391217987623967998848296898891312888421579 +9362699299759899879589911968947655251988997896874791778876389919939496782959848979971163281597161779 +1652179878596567755189593919723287659886989991199789326995581692999815373488857495418291969165215199 +9788389477191759669998798979888832998683445278988415997594187969167388689899997659918914818788982937 \ No newline at end of file diff --git a/2021/15/example_data b/2021/15/example_data new file mode 100644 index 0000000..7d9d562 --- /dev/null +++ b/2021/15/example_data @@ -0,0 +1,10 @@ +1163751742 +1381373672 +2136511328 +3694931569 +7463417111 +1319128137 +1359912421 +3125421639 +1293138521 +2311944581 \ No newline at end of file diff --git a/2021/15/main.py b/2021/15/main.py new file mode 100644 index 0000000..018b6dc --- /dev/null +++ b/2021/15/main.py @@ -0,0 +1,12 @@ +class Point: + shortest_path = [] + +data = [] +for line in open('example_data', 'r'): + data_row = [] + for ch in line.strip(): + data_row.append(ch) + data.append(data_row) + +for row in data: + print(row) diff --git a/2022/1/data.txt b/2022/1/data.txt new file mode 100644 index 0000000..15f8fae --- /dev/null +++ b/2022/1/data.txt @@ -0,0 +1,2238 @@ +5229 +1021 +2051 +4766 +2272 +5810 +4688 +2324 +2108 +1555 +1221 +4146 +5044 +2238 +4504 + +4800 +3333 +1171 +5362 +6213 +3200 +1185 +5839 +4075 +3956 +6688 +4293 +2244 + +6719 +2596 +5233 +5371 +4802 +5901 +6093 +2420 +2593 +4093 +1909 +3851 +4143 + +4353 +6425 +2546 +6368 +1939 +8550 +10505 +4718 + +16579 +11333 + +15453 +15172 +2678 +9202 +12549 + +2133 +16769 +6807 +10384 + +5130 + +5492 +2088 +4364 +2038 +4419 +7450 +3359 +6575 +1811 +1065 +3443 +6769 + +8085 +2908 +2192 +9586 +8144 +3625 +1113 +9057 +6255 + +1004 +3788 +1602 +1397 +7117 +5793 +4339 +7354 +5803 +2360 +6861 +1522 + +5499 +2694 +8448 +4969 +11138 +10227 +10473 + +4744 +8173 +8040 +3327 +2479 +1309 +5436 +6021 +4698 +7111 + +13459 +12831 +7358 +15243 +3310 + +7088 +4279 +7065 +6887 +3621 +4702 +1484 +4701 +3229 +3439 +5433 +4329 + +7427 +7116 +6640 +1625 +2075 +5473 +2507 +1544 +6361 +2094 +3899 +2610 + +6263 +5554 +6191 +6093 +5987 +2865 +5213 +1355 +4344 +5328 +6272 +3737 + +2399 +2336 +10098 +6547 +9483 +12974 + +1527 +3720 +2296 +2088 +4438 +6495 +6942 +4604 +4107 +3254 +1380 +5208 +5948 + +4000 +2423 +1105 +7756 +8917 +7394 +7770 +3422 +2047 + +67584 + +2065 +7562 +10516 +10553 +10862 +1649 +6791 + +23829 + +15750 +2204 +19115 +15870 + +7268 +5558 +5422 +5021 +8548 +5005 +6228 +7622 +2537 +8556 + +33525 +27002 + +22390 +18440 + +6424 +3180 +3370 +5910 +3600 +5372 +2190 +4435 +5612 +1747 +5186 +2234 +1362 +2488 + +10025 +6160 +11865 +10498 +8954 +11766 +9467 + +7958 +7431 +2598 +9243 +1023 + +5265 +7388 +19730 +14381 + +7462 +7931 +11405 +15307 +2299 + +13973 + +20066 +7931 +7988 +8215 + +3310 +3792 +8265 +9425 +8647 +6148 +7474 +1780 +2499 + +5298 +13922 +4072 +10671 +3101 +12829 + +16641 +22259 +1578 + +9335 +5856 +9672 +5600 +6443 +9070 +8995 +8084 +3434 + +4216 +5010 +11813 +20020 + +3295 +2690 +4680 +2403 +3001 +6708 +5748 +2355 +2128 +5044 +2099 +6000 + +3763 +6528 +10478 +4551 +9988 + +8569 +7005 +4566 +6513 +1950 +2148 +3186 +1171 +5245 +8244 + +5606 +5518 +1462 +5388 +5695 +5634 +1000 +2098 +4377 +2150 +6258 +1533 +6222 +3036 + +6084 +6129 +8881 +14255 +6495 + +66183 + +5564 +1009 +4149 +5793 +2266 +1705 + +5977 +22302 +9281 + +6193 +14000 +14745 +3014 + +5902 +17074 +11705 +9397 + +6884 +6107 +4079 +4218 +5741 +6422 +6436 +3614 +6461 +5772 +3100 +2299 + +1546 +1259 +1627 +12300 +4167 +3932 + +1885 +9182 +1952 +16058 +14592 + +16225 +16113 +10532 +4250 +11214 + +31877 +36104 + +5246 +5358 +11483 +11503 +5218 +9448 +7425 + +25508 +9115 +4944 + +9218 +2788 +6860 +7370 +7501 +6767 +7943 +2835 +9385 + +10446 +7768 +9449 +4090 +3771 +9608 +10677 +1005 + +2635 +2054 +1833 +5826 +6041 +4622 +1105 +5411 +1506 +1923 +6431 +1353 +5869 +1648 + +5704 +6247 +4503 +3083 +5779 +2804 +1199 +2892 +2739 +5607 +3526 + +2771 +5208 +3119 +1113 +3476 +4207 +5357 +2120 +3531 +5552 +1043 +3669 +1914 +3652 + +18512 +14761 +12199 +1376 + +6703 +4679 +7790 +4334 +4303 +5619 +2589 +3915 +2997 +6274 +4484 + +5025 +2456 +8912 +3731 +9568 +7868 +3151 +2172 +4352 + +2779 +7809 +3280 +7390 +4478 +7060 +4169 +7992 +8380 +8439 + +3143 +6816 +10122 +5685 +5170 +2059 +8293 +9561 + +3417 +4412 +1467 +1311 +6945 +3132 +5980 +6429 +3119 +2319 +7478 + +3223 +5320 +7368 +8486 +2951 +6262 +3176 +4165 +3878 + +2443 +4707 +1055 +6164 +1933 +5384 +2472 +4678 +1365 +6058 +5045 +3526 +2478 +6242 + +1286 +5592 +3943 +2235 +2166 +4402 +4203 +2419 +1191 +1985 +6481 +3031 +3699 +6274 + +2203 +2020 +7484 +7188 +6099 +4564 +5343 +2978 +1539 +3436 +1581 + +28968 +12842 + +4498 +2415 +5259 +3098 +1288 +4208 +5355 +4597 +4699 +1928 +5050 +2462 +1514 +5115 +1197 + +15417 +1105 +1468 +1358 + +1621 +2013 +7223 +7313 +2414 +6412 +2365 +7850 +5633 +8206 + +3811 +5927 +1159 +1085 +3270 +4467 +3219 +3170 +4662 +2590 +1022 +4492 +3701 +4735 + +6547 +15615 +1763 +8586 + +23698 +22840 +12561 + +6985 +4860 +12931 +16856 + +1083 +4957 +6887 +5155 +4573 +8668 +1336 +8058 +8624 +8116 + +6282 +1864 +4625 +2738 +3100 +3852 +6224 +2926 +3468 +5571 +1032 +2980 +2729 +1273 + +4675 +4413 +2779 +1618 +10546 +6725 +4553 + +15889 +13338 +16005 +4849 + +4016 +3798 +5876 +2734 +3833 +4346 +2636 +4337 +3190 +5733 +1979 +5696 +2727 +1418 +2574 + +8667 +4569 +7164 + +19076 +3353 +4646 +17303 + +7284 +3008 +3663 +5071 +3042 +4171 +1437 +5811 +6058 +5130 +4305 +1291 + +7413 +7982 +11370 +4943 +9583 +1901 + +1642 +7125 +2990 +7913 +11688 +2514 + +2868 +12143 +12040 +11711 + +8805 +1603 +1179 +13785 +8428 + +4162 +9190 +6700 +4467 +4947 +2815 +2319 + +64490 + +3013 +1415 +13338 +3331 +1361 + +26047 + +1780 +4104 +5757 +5818 +1251 +3359 +4210 +1382 +2507 +4818 +1130 +6357 +3442 +5819 + +10413 +8903 +6201 +3934 +12130 +8453 +10653 + +1684 +2348 +5795 +1420 +1533 +3313 +4634 +3107 +4626 +5932 +3543 +2424 +1944 +2915 + +8046 +5983 +4089 +3012 +1454 +5177 +5704 +5148 +3769 +4505 +5509 + +5484 +7059 +10998 +4037 +13095 +6590 + +1059 +1731 +6387 +7867 +5405 +7385 +4731 +5900 +7625 +4242 +5875 + +13584 +9147 +24719 + +7419 +3974 +4510 +6372 +1552 +1934 +3671 +6909 +6537 +2785 +4339 +3714 + +5596 +5725 +4532 +4762 +2518 +1155 +3972 +3028 +6432 +4100 +1883 +5287 +1470 + +3265 +1729 +3171 +2551 +4462 +4361 +4693 +1886 +4187 +4430 +2527 +2109 +6052 +5684 +2048 + +2469 +3613 +4172 +4836 +5713 +7756 +2870 +9449 +8116 + +2474 +7277 +6954 +4829 +4791 +6739 +5223 +5751 +6456 +7201 + +22678 +12732 +15221 + +3414 +4011 +6552 +4142 +3298 +2479 +4871 +6551 +3378 +4159 +2044 +1348 +4820 + +1720 +2185 +1264 +4074 +4456 +6572 +4805 +5381 +5202 +5656 +5154 +2408 +4344 + +1578 +2550 +3350 +3005 +3781 +5022 +6092 +2156 +3303 +1167 +6109 +4984 +5228 +4764 + +9527 +4255 +16366 +9609 +15617 + +1931 +4759 +4649 +1068 +5695 +2296 +4911 +3557 +2692 +5220 +2041 +3792 +1036 +1282 + +7735 +1541 +9568 +5770 +2422 +9918 +9230 + +4047 +2209 +1412 +2876 +5087 +4431 +3271 +4213 +3874 +1850 +2848 +3097 +1604 +6014 + +4123 +5797 +9239 +4185 +1985 +8496 +12133 + +5966 +3182 +3301 +3752 +3076 +5895 +4127 +1256 +2765 +5702 +1099 +2699 +1982 +3853 +2466 + +3231 +16587 +14341 +12450 + +3252 +5245 +7317 +3264 +1597 +7616 +7997 +6473 + +30334 +20535 + +3226 +1900 +1115 +2451 +2544 +1454 +4748 +2103 +1603 +4768 +4127 +6880 + +7664 +4890 +7471 +4256 +4500 +7972 +7735 +1608 +5403 +6407 +2323 + +16144 + +17580 +15361 +20625 + +3069 +4258 +9309 +4430 +3506 +5655 +2470 +2554 + +6720 +4729 +10030 +6668 +11714 +9766 + +5695 +3592 +2401 +6246 +6326 +3577 +7170 +2956 +7886 +5671 +4073 + +9308 +6580 +3406 +2614 +10222 +11738 + +5705 +5017 +7426 +5464 +7683 +7143 +1430 +3296 +5567 +1246 + +6068 +16761 +24717 + +8627 +4695 +3905 +9375 +2530 +2468 +8353 + +4233 +8937 +4755 +7728 +2911 +8201 + +11742 +9806 +9398 +5486 +3986 +3737 +4431 + +4521 +6395 +10148 +10058 +5169 +5924 +6215 +9839 + +3822 +3938 +3255 +5686 +4069 +1748 +5290 +1172 +4756 +5298 +1445 +1151 +1757 +4880 +1005 + +7801 +5402 +3736 +1269 +3067 +6793 +2603 +2757 +4267 +1098 +1487 + +2050 +2462 +3498 +1989 +2954 +5902 +1742 +5812 +1725 +3039 +4056 +3462 +2234 +4982 +4204 + +7154 +7180 +9175 +7523 +11486 + +2268 +14293 +3172 +13819 + +2565 +5565 +7335 +3609 +1350 +1829 +3223 +6861 +3201 +2821 +5546 + +27227 +6603 + +27999 +36577 + +1899 +5224 +1904 +4450 +4721 +3288 +2261 +1482 +5854 +1855 +3314 +1240 +2040 +5785 +1321 + +5636 +13866 +11081 +7189 +1212 +3350 + +1128 +4191 +5944 +5123 +1758 +3625 +4668 +4213 +2290 +5714 +3182 +3927 +1452 +1336 +3944 + +5180 +3316 +5766 +1930 +1360 +1494 +1686 +3687 +1163 +5291 +2004 +5156 +2966 +1079 +6110 + +16746 +12254 +6000 +5315 + +2494 +6563 +1214 +5120 +4184 +2958 +4187 +3182 +4165 +3772 +5885 + +2563 +9144 +13383 +2614 + +1967 +6950 +5760 +11165 +2977 +6822 +11217 + +4641 +3789 +3318 +7045 +2157 +5785 +2074 +4366 +6727 +5210 +1268 +7154 + +1050 +4906 +5598 +1917 +1037 +6393 +1109 +2455 +3396 +2416 +5997 +4541 +3292 +6169 + +3863 +4824 +3689 +1274 +5440 +2468 +3532 +3726 +2534 +1350 +5809 +2808 +5413 + +5625 +9547 +9049 +4953 +10529 +5656 +5423 +10330 + +3362 +3192 +1803 +10128 +10464 +6895 +7316 +6016 + +4023 +6108 +5742 +6475 +3507 +3644 +2447 +2746 +2025 +4809 +5356 + +5481 +5028 +3434 +2592 +2764 +4581 +5131 +6579 +3688 +3831 +2638 +6920 + +15426 +10544 +15670 +10196 +10450 + +3950 +1578 +7483 +6322 +6168 +5071 +1959 +6613 +2528 +1155 +6651 + +8933 +7371 +7241 +2825 +3312 +5629 +5569 +1476 +7875 + +6063 +8359 +8025 +7009 +2844 +5998 +2172 +5087 + +3012 +4589 +2428 +4325 +2476 +4431 +1084 +1870 +3717 +5620 +2078 +5550 +3696 +4003 + +12043 +10021 +12260 +11676 +1358 + +1906 +1415 +2453 +2656 +8867 +11861 + +2003 +8051 +3821 +5617 +4339 +3956 +1460 +3683 +3041 +1109 + +5108 +3195 +4262 +3074 +1153 +5069 +3090 +2216 +3822 +5849 +5349 +1722 +3544 + +3131 +7765 +5030 +7322 +4358 +3805 +6231 +4337 +6983 +8058 +1750 + +4404 +6696 +9425 +1185 +8939 +7995 + +20444 +12374 + +4697 +4969 +3703 +3355 +2636 +2864 +1906 +2337 +5805 +5042 +2531 +4525 +4332 +5240 +2334 + +2803 +7814 +21563 + +1134 +5051 +6097 +2678 +1589 +1077 +3220 +4583 +5404 +4625 +5550 +2604 +4208 +2707 +1403 + +31477 +25502 + +2395 +3341 +4197 +5847 +2087 +4219 +3782 +8698 +1857 +4450 + +6868 +1572 +3798 +4386 +2165 +5536 +3098 +4647 +2891 +3992 +1417 +4182 +2526 + +5524 +1679 +1359 +6686 +3481 +5993 +5716 +3492 +4518 +2286 +5154 +4729 +3745 + +2077 +1960 +2921 +5233 +6199 +5723 +3587 +2224 +2973 +4124 +2532 +5729 +2725 +2212 + +5547 +27031 + +2663 +4381 +2660 +3011 +1553 +4661 +4388 +4255 +4149 +5342 +1474 +1773 +1643 +4990 +2785 + +13510 +11941 +11601 +13234 +14555 + +3141 +1458 +2337 +1301 +3536 +3120 +5346 +3305 +1966 +1317 +1306 +5272 +2471 + +14739 + +1090 +4088 +3187 +6949 +3188 +4069 +1081 +1362 +4687 +4987 +6125 +4276 +5416 + +5420 +4661 +1134 +6794 +6879 + +3519 +10646 +11068 +7566 +1738 +4000 +6352 + +5828 +4345 +1475 +5378 +3732 +3484 +1380 +5713 +1288 +4980 +3355 +5957 +4201 +6060 +2319 + +1567 +6755 +4660 +5039 +2185 +5556 +1548 +6784 +7435 +8673 + +7674 +6663 +4682 +7994 +6190 +5627 +5437 +10249 + +6224 +6926 +3873 +8730 +3293 +5941 +4277 +3248 +6169 + +33991 +37153 + +10839 +17054 +2274 +16762 + +3539 +4987 +5992 +1987 +6262 +7251 +3518 +2978 +1940 +7579 +4792 + +15466 +17473 +11506 + +6225 +1583 +3381 +5832 +7437 +1738 +3851 +4062 +3985 +6128 +2106 +5395 + +11595 +11726 +4915 +6481 +10978 +11348 +6436 + +69359 + +7954 +6267 +7397 +2410 +3368 +2405 +2653 +10068 + +1229 +3516 +2863 +5960 +6461 +1208 +2495 +2725 +4777 +3103 +3609 +3455 +6118 +3885 + +10757 +17804 +13767 + +13854 +2648 +25818 + +8694 +4841 +3987 +11448 +12847 +2139 + +1320 +11876 +13686 +15670 +3638 + +11207 +5853 +16863 +6347 + +3506 +1460 +2170 +1558 +4391 +5749 +1559 +4347 +1848 +2377 +2287 +2061 +2944 +1859 +3770 + +1004 +4706 +2800 +5717 +1363 +4130 +2804 +4492 +5275 +6138 +1741 +4835 +1608 +2935 + +4281 +4949 +3882 +4723 +3772 +1715 +1966 +2851 +5124 +6875 +2605 +4571 +5076 + +5090 +1237 +4259 +2706 +2207 +3303 +6721 +5107 +5765 +3215 +5590 +1299 + +3633 +5271 +6428 +2905 +3439 +1169 +2324 +3467 +5839 +2215 +3825 +6168 +2515 +2639 + +4152 +3191 +7939 +2909 +7758 +8458 +10068 +3091 + +7840 +3473 +1536 +1749 +7930 +1987 +3695 +4027 +2904 +1083 +2398 + +1712 +3774 +3351 +2025 +2892 +3478 +3597 +4129 +2755 +3052 +1201 +1473 +4412 + +11300 +11432 +8714 +8717 +3686 +9938 + +2212 +6074 +1598 +1582 +4499 +6651 +4829 +1075 +2163 +3523 +3353 +6924 +5548 + +1300 +2708 +4287 +2338 +6756 +2542 +1000 +3609 +4850 +4073 +4370 +1536 + +8355 +10196 +9152 +7652 +6908 +10396 +1328 +2985 + +1636 +5454 +2321 +8639 +7510 +2116 +9825 +2967 + +7415 +5557 +6905 +7370 +5778 +2604 +5217 +7410 +3024 +1438 +6475 +4944 + +6302 +6308 +7719 +3740 +1278 +6259 +7667 +9084 +5198 + +2829 +4397 +3821 +4890 +2281 +3494 +6039 +5283 +3650 +2374 +5767 +5077 +3983 + +13986 + +4806 +1352 +6248 +6441 +2520 +2442 +4442 +4725 +1529 +4924 +3382 +6294 +2256 +4248 + +1914 +2192 +2583 +3469 +6484 +3053 +1601 +2778 +4338 +1295 +2052 +1196 +4080 +1226 + +5912 +5781 +4362 +4609 +6503 +6887 +6190 +6875 +5729 +2286 +6269 +3697 +6917 + +13964 +18073 +1619 + +5598 +4795 +3109 +1533 +4062 +1070 +5467 +1791 +1786 +1690 +5663 +5442 +4007 +5523 +3620 + +5587 +3778 +3342 +8950 +1061 +1562 +4896 + +22883 + +3218 +3454 +2771 +2855 +2949 +4683 +6479 +7767 +2638 +5846 +7089 + +9225 +6021 +7659 +9858 +9055 +1762 +10125 + +12693 +4685 +19506 +12078 + +6854 +5988 +5689 +3777 +1147 +7286 +6738 +1202 +4855 +5018 +6886 +6392 + +7804 +1729 +9762 + +1753 +2124 +1404 +6974 +5381 +7212 +3108 +8010 +3290 +4152 +6716 + +6101 +1846 +15812 +14339 +2432 + +2278 +5499 +4614 +4429 +3867 +2956 +3488 +6817 +1576 +6129 + +3185 +4667 +8304 +2137 +3003 +4787 +7451 +6037 +5938 +8541 + +58634 + +5507 +5347 +7888 +8768 +8159 +3449 +8288 +5246 + +1701 +1682 +4615 +2661 +3590 +8912 +10306 + +8832 +2882 +10016 +4781 +3901 +5466 +8481 + +6374 +3087 +7462 +2743 +7047 +7400 +5802 +4531 +5299 +1025 +1437 +5227 + +6500 +2359 +11048 +2806 +9293 +9680 +10283 diff --git a/2022/1/main.cpp b/2022/1/main.cpp new file mode 100644 index 0000000..402c18e --- /dev/null +++ b/2022/1/main.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +int main() +{ + std::ifstream ifs("data.txt"); + if(!ifs.is_open()) + { + std::cerr << "Couldn't open file." << std::endl; + return -1; + } + + static bool last_line_blank = false; + + std::vector numbers; + long total = 0; + long most = 0; + for(std::string line; std::getline(ifs, line); ) + { + if(line == "") + { + if(!last_line_blank) + { + numbers.push_back(total); + if(total > most) + most = total; + total = 0; + } + last_line_blank = true; + } + else + { + last_line_blank = false; + total += std::atoi(line.c_str()); + } + } + + std::cout << "Most: " << most << std::endl; + + std::sort(numbers.begin(), numbers.end()); + + if(numbers.size()) + { + int three = 3; + long total_total = 0; + for(int i = numbers.size() - 1; i >= 0; i--) + { + if(three-- > 0) + total_total += numbers[i]; + } + std::cout << "Top 3: " << total_total << std::endl; + } + + return 0; +} diff --git a/2022/1/main.rs b/2022/1/main.rs new file mode 100644 index 0000000..9a7e4b8 --- /dev/null +++ b/2022/1/main.rs @@ -0,0 +1,38 @@ +use std::fs; + +fn main() +{ + let contents = fs::read_to_string("data.txt") + .expect("Could not find data.txt."); + + let mut numbers = Vec::new(); + let mut total = 0; + let mut max = 0; + for line in contents.split('\n') + { + if line == "" + { + if total > max + { + max = total; + } + numbers.push(total); + total = 0; + } + else + { + let i = line.parse::().unwrap(); + total += i; + } + } + + println!("Max: {max}"); + + numbers.sort(); + let mut top_three = 0; + for amt in &numbers[numbers.len() - 3..numbers.len()] + { + top_three += amt; + } + println!("Top Three: {top_three}"); +}