commit 639ef038b21551ae8b73895aa31c98805213705e Author: kirreen Date: Sun Dec 3 17:03:15 2023 +0100 day 1 and 2 diff --git a/' b/' new file mode 100644 index 0000000..05aac66 --- /dev/null +++ b/' @@ -0,0 +1,4 @@ +day1a +day1b +day2a +day2b diff --git a/README.md b/README.md new file mode 100644 index 0000000..40604a2 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +messy solutions for simple problems diff --git a/day1/day1.c b/day1/day1.c new file mode 100644 index 0000000..d083e6e --- /dev/null +++ b/day1/day1.c @@ -0,0 +1,50 @@ +#include + +int main() +{ + FILE *input; + input = fopen("./input", "r"); + FILE *output; + output = fopen("./output", "w"); + + char inChar; + char numbers[4]; + numbers[2] = '\n'; + numbers[3] = '\0'; + int numIndex = 0; + + while((inChar = fgetc(input)) != EOF) { + if (inChar >= '0' && inChar <= '9' && numIndex == 0) { + numbers[0] = inChar; + numbers[1] = inChar; + numIndex = 1; + } else if (inChar >= '0' && inChar <= '9' && numIndex == 1) { + numbers[1] = inChar; + } else if (inChar == EOF || inChar == '\n' || inChar == '\0') { + fputs(numbers, output); + numIndex = 0; + numbers[0] = '0'; + numbers[1] = '0'; + } + } + + fclose(input); + fclose(output); + + int sum = 0; + input = fopen("./output", "r"); + while((inChar = fgetc(input)) != EOF) { + if (inChar >= '0' && inChar <= '9' && numIndex == 0) { + sum += (inChar - '0') * 10; + numIndex = 1; + } else if (inChar >= '0' && inChar <= '9' && numIndex == 1) { + sum += inChar - '0'; + numIndex = 0; + } else if (inChar == EOF) + break; + } + + printf("%d\n", sum); + + fclose(input); +} diff --git a/day1/day1a b/day1/day1a new file mode 100755 index 0000000..db2a303 Binary files /dev/null and b/day1/day1a differ diff --git a/day1/day1a.c b/day1/day1a.c new file mode 100644 index 0000000..bd098d6 --- /dev/null +++ b/day1/day1a.c @@ -0,0 +1,34 @@ +#include + +int main() +{ + FILE *input; + input = fopen("./input", "r"); + + char inChar; + char numbers[4]; + numbers[2] = '\n'; + numbers[3] = '\0'; + int numIndex = 0; + int sum = 0; + + while((inChar = fgetc(input)) != EOF) { + if (inChar >= '0' && inChar <= '9' && numIndex == 0) { + numbers[0] = inChar; + numbers[1] = inChar; + numIndex = 1; + } else if (inChar >= '0' && inChar <= '9' && numIndex == 1) { + numbers[1] = inChar; + } else if (inChar == EOF || inChar == '\n' || inChar == '\0') { + //fputs(numbers, output); + sum += (numbers[0] - '0') * 10 + (numbers[1] - '0'); + numIndex = 0; + numbers[0] = '0'; + numbers[1] = '0'; + } + } + + fclose(input); + printf("%d\n", sum); + +} diff --git a/day1/day1b b/day1/day1b new file mode 100755 index 0000000..2d8f4a5 Binary files /dev/null and b/day1/day1b differ diff --git a/day1/day1b.c b/day1/day1b.c new file mode 100644 index 0000000..bb3a5ce --- /dev/null +++ b/day1/day1b.c @@ -0,0 +1,80 @@ +#include +#include +#include + +char *firstMatch (char *string, int offset, int *digit); +char *lastMatch (char *string, int *digit); + +// array of strings with all digits and human-numbers +const char *numbers[] = {"one", "two", "three", "four", "five", "six", + "seven", "eight", "nine", + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; + +int main() +{ + FILE *input; + input = fopen("./input", "r"); + + int digit = 0; + int value = 0; + int sum = 0; + char row[100]; + + // use fgets + while ((fgets(row, 100, input)) != 0) { + firstMatch(row, 0, &digit); + value = digit * 10; + + lastMatch(row, &digit); + value += digit; + + printf("value: %d\n", value); + sum += value; + } + + fclose(input); + printf("%u\n", sum); +} + +// function with input offset and string, returns offset (and val?) +// looks for every string / char, return lowest offset +// to find rightmost, repeatedly call this function with offset + 1 +char *firstMatch (char *string, int offset, int *digit) +{ + // this ptr is 1 step outside of the array, because the + // relational operators in C are only defined if both pointers + // point within the same array or one step beyond the last member + char *first = &string[99] + 1; + + // looks for each number string from numbers[] + // and remembers the lowest pointer + char *match; + for (int i = 0; i < sizeof(numbers) / 8; i++) { + match = strstr(string + offset, numbers[i]); + if (match == 0) continue; + if (match < first) { + first = match; + if (i <= 8) { + *digit = i + 1; + } else { + *digit = i - 9; + } + } + } + + // Pointer unchanged? No match, return NULL + if (first == &string[99] + 1) first = NULL; + return first; +} + +char *lastMatch (char *string, int *digit) +{ + char *last = &string[0]; + int offset = 0; + while (firstMatch(string, offset, digit) >= last) { + if (firstMatch(string, offset, digit) == NULL) break; + last = firstMatch(string, offset, digit); + offset++; + } + return last; +} diff --git a/day1/input b/day1/input new file mode 100644 index 0000000..bc93c6b --- /dev/null +++ b/day1/input @@ -0,0 +1,1000 @@ +sixrrmlkptmc18zhvninek +jcb82eightwond +twofourthree778nineeight +sqpxs1cgcrmctlgqvzxbcjzgr +nqkjxbmbpkz9eight8 +one6fourfiveqndtrvgkkgthppnine +zbrbdpbfcfxcqq5oneninejfgqpkfn +hvlstzgvmjfivefourqjqtxdjmbxfour4four2 +13dzbmbtl6 +fourone2pmlxzzbmnfxg2 +3fourrbvvlrsrbb2858 +vlz4six89 +75threeb +fourp783fiveseventhree +2gxvcbsmn6 +896 +dnblxtxxpstlsix56 +4fivecl185 +onefk8sdljtfv37zsxsxrv7qvrpnmd +fourdvhzp7foursix +seventwonineseven27jbrqpxfx8 +1threenine241gnrdfqn5 +sixnrsqdgmkvs7sevenkgjgtglmdq9dkdzsdqmq2nptbxnxghm +llbkdcpxkg1tnmnmrbskpdb +zb7nvjz1eighttwo6nine +5threeeightwor +tgjmdbr4sixone5 +4twoseven7tjmklbl +lt2vqgbkzjpcjzeight3frfzqgbhvlx4 +4sixseven3xbmsfxrrvv2st5 +gqlp7 +h137four +3three7three7 +nine9sjlzcpjvhcnbhbthz4oneb8kfb +jlrjz5two +sixthreeeightsgnjnmffq3 +sixone87onepclf3 +two4six +5dsnxrcfxb4 +fiveninesix4 +eight9jhqttcplxhtjthreevncsfnkpn +4mgqksbchbcrxp5fivefourlzlzp +xhzone6 +7nmcxjlmq94twofivethfccvn +six769fourtwoseven +two41stkvkhdgthree5 +jvpftbhljmcttkr5one +9ldhzhplpzttwosevenblfxfdfour +fivekcfmfmndbhtwofour32 +49qsslhxjqv1tsfqhkg +five2zzstkq3935sevenpbb +8sevencxvfbkv2p8 +lsmmnpnfourhjbfk67 +fourtwo4onethree +1jf1eightdhvnclf2four7bmdvh +tx4xczz1 +5qjlqp +sevendmzqnjdnoneh1 +72seven7pvjxdlsix1 +four1eightvbbjh +8451 +fivethreesdtmtr5four +gqhtwone11ninethree4ptjsqlg4fivenine +one7xctgtrtwoeightwovkv +36eightsixeight4xnmhvzrnbb6four +pjrtblbj759xpbr6 +hcbzmzqssh72eightthreesixgdmfivelmctqrz +rhkctwo5twonine2 +cdptxn6sevenjktrlzlnlqxdtwoeight +six36fnqmdcjgjgbqgqcgffivetskhjhkpdqfive +qmpm111nine8 +73pcctxthreetwo4nine3fivetwonehfs +nineeightnnfsixpt3kbbqfkhhn +bvpmkrjmzkvdnbhdnine47 +26dmbqnt4oneseven5qvxfhl +2sldrlqzone1pfdlsqdgpmnktdh3vtplbsvbx4 +238xrtqfcfgsrmrhkxz6 +5eighteight5sevenseven +qtlnninesixxjnmxkntpf9six3pbrpljxhb2 +xrmkj137tkxktdnine5bnnhp +gkqzprfcrfcgpxnvggsnccsrrk64oneseven +zzmgmkvgrnknsq6tjgktmbghkl6 +xeightwoone91 +9j +eightlm63 +fmctjfspmkblkvjtrcjdfhrtwo4fourdnkrzh +3rb73 +8mkzqthreeqtvhc7 +qgmbchqqzsvx45eight +oneknnlhjffrxhdzbgj1seven +pv1fourtwo +fxvgcx9vrlqssrrqvl94 +sn6 +57twoonefourthree +gtwoeight6njfdpvcslcponenineqrxjsf +8six1two6jkvltvgjfjsdn +fourrxtjhcdxhr1fdqdj +one2onefour +three3four6pphqkx8vrgvbtmqckpz +nine5nskhdvvbnineone +7131eightone +one1sgckzz +sgpkknine6threehkqchz +4twoqvbpxzpjj1njqtphjbr +4pfcfnfqftbfnxds +bmhthreecsslmgpzzddpxfthreefllkhdtrlj2 +9threeeightninefqdfptj +ninenfbsevennkngdg21 +1fourthreeonethree3 +tjpjbmrsevenhcllbgdqxlctdk5 +2srjxhvbtqponefourtpsgthckseight6bjvnc +68b +vrcqnglljm19nftnzzjdzhvhzrgznine +fivensjpfvltr2cvfhkcfsvt4pnmttrgrr8five +tgzdbrgdfoursevenseven8fnxghs +fourmhmql9rqkpvpgj7 +7mgk +2z259nzfqfdhthreeftwo +eight57lzhvpjcxpfivevkszhzbfourfour +sixone984two +threezdvkl15hk9eight +4dxxpjttvsdtwofivenine +99xbp8fivemcvonefivezlndv +seven7six8fhxhxqgr3fsqqqmzdtj +one579vdplvfghvf +qzzthree1kghtwomnlnxpkmeight +44eightonevnzxchddbnzrfpvxsix +fivefive5zfsvhfpkzzfiveeight3mzrkkk4 +46xxzbffbmgeight9dcmtwo +tvmgkxbrtdv6mzcpkf +kvbczdkgzrxsxm3one557onevzdhzgn +xrfxxzlmtlmvgpvninethree1 +4rnzxgfplmnmjppqv6txztmmcpnf +five47fouroneqqrj +nine5cxxfcqmeightjqztkdqxnpqthree +2zlvnvptqkzsbvp9six4bfhp +bhvkfxhdnrmkfjvsmkt6eighteighteightzzvpddg +12seven49six +5rstmpbrt5fiveone3one6 +24four +fiveeight9foursix995 +8ktwonxzvt +gf6six39zxvzcfbtbxkvqrps +gqvpkvvgcxctwo7 +52mhhzfivebpn9 +5onethree +one2cxzklfh9 +flrtmhfm985xmkpcdhr +4ltqdsixfour7483 +one9nine26gjtzn9 +773xhnnch78 +one7sixsixgghp +5292zljdfhjseven +seven3onesixthreekz +seven5seven3seven4zgtnnkkgseveneightwosg +eight9vnfsvksv +5seventwo9 +onesix7 +4one3two35nine +5mmrdtrzctqxggtzhplfnphgp +v94rpkdzeight6foursix +four1mslzzghlpjtblzfour +scrv2four4dxfqpcvnml +8sxjs1141fivefive6 +3eightpqsxgklhkbkdsppone9 +fcvpsvmsevenfivesqsqvhm6hqmshds +5sixfive677 +kgmpqfgjtk9hghczzhpsgfhsnghdxngd4 +2xzph98twonesj +kphxn9 +sixeight625ssnpmlpsbtwo +twofourhbdmm97 +ndseven1 +onelf51 +88khzmskgldcgttzqnzxdh4bnvxzgdr +lchrtnsxtwo7749lbdgfour +mmrktfqvvkzrglcpkfjrlm34 +5six7psdcckhs413threebqnr +seven5oneqfourkf +hsngkzgnfninegmjvtmtchdgs5grf +8qxlscsevensix8 +bvbhc7dfplnk +5jjcshzxhgzs1mpqm9 +vzqcvvtqjone7one +one5threeseven +hbtvthree1 +8five2lonecflvtjqh9eight +xckhrnseven9six +vggclcqcnfsix8seven924j +jfjlzm1fivegplflrcvsix8 +zd6psbxlv +mtcsbn2 +eightd29rlcd4 +six41one6csgdbndn +four1mh2fourdfktmszp +14nsnlqqlgfourxbzzxfztvbxsnxttjmktcxkkkzfphppsczqoneightgc +9vlkdznbjt5zqthreetwonedv +hqqtrzmknine1 +6eightsixdmkgnvkjqsqsdhlfzpxqpqdzrlvxm +8four2xcztwo +mptznhrtsq5fourfour4one +8zxnrngjgtgq +7s +68zrdjfxfiveonerbrqbzxpnhsxkbsqsx5 +2eight4nine +fiveeight6two +12jvtjssix87 +qcxtdnzhtj665bqffftxdp +gsxeightwo37v1 +fxbvtshpbldxfdnkk69jhvgktlthree6 +2hbxztgsmqsgg57 +five7sixfpjqdcbvxfgzcfgb +soneightthree29qlsddxxfl5 +cn2 +29six +skrbzfmsixp26twofournine +two8onepcddklbzfoureight8 +nldvphs7dbqxsfflxx4 +8pngqfour +ninefive69nineeighttwo6 +nine54lnzkckcvteight1bhznxgsixeightwor +five18sevenvgktwo47 +1eightkcmhsb +djcmqbvmfsztncvvthree5 +sixfbbhffjnrz1mtcfbqs76llrvjghtfive +five5bkxn4 +8eightwoc +khvcvqthree7rthjfivezdglhfnstbtjglxlpkztwosix +72lxsfkmzrb1 +nmhqmmxlqnpfour8 +zbgtwonezksvdvfqzthreesix6dlc5 +6zvn6 +5pmrjmgvsdcsjlg86 +twoeightseven21cvntvr +3qmqjjqtjskqtthree8sevenxm2 +four5fourmbdx +jpdmdb35vkjdflmlt +224 +six3msltlcgtrnttcvtkrnine +nine1d +eight6eight6 +sevenm7 +threelkngfmstfour9ninelj +5rjbbxmchhfhl +1two6679twozcgbbldmznvhd +eight2tgxkhtfmrk9sevenxntpkhkvjb +ninethreetfgtsh6ztcxczsxr +9sjzjdeightmbvrvx4 +6fivetwodszsmffjbh +sevenfivezcbqhhsntfbpkz3one3 +7onenine11 +glghbpvrbfqsfvnvpxlb5vvqkt8eight +rvhqbhlmonenine96 +npgvjlkdxmsevensixxrkhlt5 +mhqf52scsgsxtwovcpq +zrvznqpcjhtsghfb7 +five8threeonedl +8threefiveknqhmm4five2 +xdbd4cchcfpvzthreenqqbdkfbnfspmklhvp1ztzs +fourmn932eight6rjq6 +tdj3three +2nine98lcpnbchtcfqvqmbrzlhzjjrcsmzgmd +1tfive +6cbhhqrvjkzfive4pbnrr5hbvdbxln8 +2eight8three +lvveightwo9ninegrlptxdskq +3xpcpqkrznrgq72six +9pnczone4two4tzjktcktzeight +6eightldtmkj +pjc9nvbhjmhnine +bznzg4sbdmhglddnvbrxtr5nineeight6seven +51four7eightwopkv +323 +3cxmrtnjdonehdsxlfneight +7kfsxscrsrffour +six2sixthree6 +2nljlkkdoneseven4dvkplq9eight +31six9jqrgzmjlk +ninefour659 +zjcfjzbfivesix2bqtnbdzlssvr +4onehzrmb +6dvfnpbdnr1fhtmdddqx +phvgzphlvqeight1 +22s5 +fivetwo9 +gxczffbjgxonerhxklzvkmp89 +fbrxkzpsmb59997 +tmf6 +ninefournine8 +42fourtwoeightsix96 +vmhqthreeshcdtwo2three28 +lpzbfpfhxj8rbspbrjgd882 +9threesv +6xvqch +6sixdthree5sevensbxnxvsixthree +five2jzsconeightm +three9three69eight +7789qfhlmznpqzrg3 +bbf5dtpqhs2jstcbkcfmc2nine +eightmpppb6fpdonecrdrbjqtc +nineeight1nine +four2tpqrhnj8fivexmvhtsfive +gbzzxdd8 +onehrjlhprzz5 +fourzxxpl2onetwo +5four5two97 +threeeight2 +5one68656scpqt +7qljfddcld1czjb6fivehtqcpnbjfnmrrthree +9lrzbkvqmjfv5qkrlmjkrx436 +hfivetwoxgjkfc72two7 +gbbbnscg6 +glrhbfrfivehfkfplnrt49seven +nine3sixninefive3zksdxtbbf +ninesevenvgnlhpdb123twogfvscpk3 +fivefsrtpxzlltnfnine1ninevzsxbnine +7nineone44bdxoneeightnfpckpdjsq +rcrtqnnrm15 +eightfive8 +eight2dqzcjfkfsfoureightfmjrpdkqj9 +one69twornine +fivefjpzeight6 +5qxqdcl7qzfqvmsfnnine9fouronedmdg +7sevenone4four5eightone +phxdrlcd3two +fnoneight12vqscqzxdgdzsvfqggbt9zphpvndl +eight6jhjqrvsgbteight2 +gdhznsvfmdeight6jpvdmrdsix92one +onescsrmks474ninetwo +51bmcpkkttczbsbhvfdzgfbccbllxskmtxvs +61eight +qfplfour7fourvhsbxtzrb7three +ninefg8two +8seventxeight3gzbvjmbcmzoneightrlx +16twobghcqnfiveseven +one26sevenone +three4sevenone996fplzjqh1 +pkszjvhtdg9six +eightfcbbchqtxbvzmdnj1fourkvldvbzltm8 +5sevenfivevhcrl78 +7bjmr96ghmzhzh641 +seven71 +ljstghtkzcthree64two3hbvbgconethree +9fourninednbrkdfnxeight2zppqsnx +zfjm8ktwofivezr +qtfvmhvpthree4fivehsxkxnpchmfcvr2sixfour +ninetwo3dthqone +six2ncdntspl1fivenmxzxh81 +twoqtpfbfive8mhvkjstfp7gddzmmdnxqrvp +threesixone3tgbtbone81one +8vqmtnfkhm1 +zgtldxtbgxgfour8eight65 +hbk6threeseven +1tpnrcfivejbqllpgx +twotwo4xcppqxftxeight8six2 +2seven5bnvqdfbtwo8eightsflgdzqczpcf +two45 +4kqrscxrsdveightflhrmcpxrnqfrzrsixkj5oneightbls +5jttone1six +nine95eight3fourseven +fivepkknbrqfkdhk8ndt7three +sevenfivetwo4vqkjlznxl9oneseven +nlzrrsbqllsevenfive94threecmzbp +qnszclmv6eightthreeeighteight1nine +oneninesevenmmqpd6oneninenjvcrbgnjm +jptwone67kqxkdfscsjmfseven14kz7 +threexzxlgceightfour8 +3fzbtwofivefour6 +hdr4plslvxqxm6sixnine +one62ttrpmhjvfk1 +foursix5phpfcxzrrbhsv +eight81 +7cfdqxdqjq +69eightfive +6nphsmsqsevensevenonefourbsmg +sixeightsix9vk +freightfkthreesixfour6hzdmrcqzbs +vclmkqdqeightseven5eighteight5bbvzqlslt +nfbzpffd198six +jpeightwofivethreetfzgnpfive1 +sixseven2trjjh +4ssfourtwopqsgvbvktk +five8twoonefksixseven9 +5eighteight2g1six7 +fivethree9twonelgh +4fourxbnhjfoursix +lqdspqgjnnhxnine99oneninefourttpskhdzhq +fskvvccb178 +eight3twogsjlqhfhr +sevenklhxjjlzrx7sevensix +84nine5zqjbhjsxvn61sixone +two9htsj +sixfiveninep75tgggjszfbsix +sixbrthjrnnvmqgb8 +tpcb25twothree +9fxkfzmqdgll +cnqjxttzpthree2vfxrklhrmgsevenvsjkf +tljlxbfbk43 +mcpjvsevenseven5three4 +cvvckfncxjlxrp381four1 +63vksn7six185nine +fourhbg8thjnmvlctsixninejpjkxqhcljrvgrm7 +649eightone1four +nrmjcbpdsb6fourpcbpb +one6nineone65 +g2x36 +nine9sixvbnzsqbrj +four3sixhfngsjrsnth977 +seven9692dfchqbdzztmfztl +six1pdtgbdhzmqtmhz6ninetwo +rzjssbsz92six1four +4sevennineninesixvgjsxqrgnbgfpzpggmkzjrq +5onefourthree7seven +9zgjt +eightnsrq37qhthree +czknlpbntwoseven1twopfhfdhrkgh8sevennine +3eight9 +sevengltpjfpkb32ninetwo5 +five8ninehxgkcfxm5fthree4 +8three9drtnqx +lldtcdsfvvqcsvprgggnfourhklqqsjbvttskq3 +vrxmtwoftjngsfour1sixlfbdkxbppj7 +khvvrrhc2eightfive9 +kmsdthsbffjxdgfvmppgrfglxkplv2pvtpm48 +49gzlbspqv45qdsvp9five +threehzjcp6threed4 +sevenone6onefivefourcpznxpseven +85zc6 +eight92fccninefourthree +36hpqnpmmxrhsftwotpt +11six6 +5vzkjxh +4ptvlmns +19f41seven7twonesmr +39threevrvjhfpzmp1seven38 +five6eightfourqjgfvhqjclt +ktjsgzqkzgplz85 +242sevensevenninelrxhqvddb6mbfxmx +54threekfcqtpfgeightvlm +sixfivetwo82seven8threes +vtckldxdssix5mfjrmhvtlninemq47 +977sspjhmddkznine1sevengjnm +ninexmjfhhnhhv3ckndjbdxjcfive4 +toneightnine96 +twoxfsix5qtjghvqnjseven9six +fflplfmqx73fivethreeqmsncsl2six3 +xxvbfcbb7kkjzgmtvp38df2gcfhjtt +knthlxc795foursevensevenseven +twof91two4 +four9sixjkjqcrnine9eight +sixnine1two5 +mrrhthtfbszfxqpkhs57 +five985tmcr +l4eight +twosix7 +ggztprpshxbgbvgllfjxr7x2ql +9one6nine3xttqxqjnjsvknzg +1nine8172 +1npfxpgcmbckgtcgvlksevenjfdbs8sevengqdcsn +eightzbjqsix613nine +sixkfczsxbnpfourzsninegtjkg5five +47four4gtwofive +jczqhs41 +2jzmpchxv +xxxx8eight36sixpzpdvvvvntwo +two649nine6 +four36sixhfzslcnhpssixthree1 +9eightninefivez +933cvvf1sixsvkr21 +zrsnsqdcfmxm9fsjqfzd7 +five7sngmpcz +sevenlzrzgddch5dnvvkzf3sixsix6dnhtbkq +5lbdtxdzoneone6 +vkjvhl4mslfs +pvgvmtxvsjdpth39 +gg83ltnfcsv4seven +lksmpxxd91dnkjq1fktbfmvgh +djfslttn2 +onefour9three8sgbtlbtsmh +qnrrtjxtninefive88sixmhhbqs78 +mgrpmfvvxf37onefour478 +two26two +4three3five767 +eight5l +3pm8cpkczckxfc +6nine5one2841phpgfxhfr +4threetwofxblrfnfhj8eightone +ninetwotwoqk9fourqmzzz +211127mkhpmsr +mssppjqvlt75xjccfcjfiver +57mfour +rdj6smlgs +gjllvdmmgktwodhnnbsfourbvqvlvpcv6v +seven2fiverthjdnfqgnine +7sixtgns8xfmrx +sixdcfpbdt3lcnlsxxone1 +9jxpl5sjzqxxk9 +four2bzcdrbmfiveseven1four +jtwonefivefvftvbpsptftbvpxzz2fhgmlqrfsevenvrznjjlchbqtrgbb +4seven3crjjzzbseven78gkcjf +djnqxxtsevenpthdvddhdm5977three +threeonethreex92bnmpv3 +klgxtpg4one3kcnhfqp +2dhsbc98 +mrqfvbgjqnfpggnn2spmjkvbchpzpcgcmzvcddtl7seven +3xccrgznljpskhxnqbtjtcvmrmthreef +4jphblzdzpfouroneone +68twotmmsdvxtwotworrjvzfiveseven +864861 +1qzcctgzsixjtlztmdrtd2 +4seventwo62 +one8kjkjvtvhfive6tsvqnine5tkdsv +7m2 +twoeight77sevenfs +vb8gflhvvf7hleight54 +fourcxmkbmmzbhz494gncgbsj +bjzzsllj5gphkfnrncp3eightnine +four73 +psvtbtf93zgdpmjxrmvsjmceightpsmhvhtfrthree +492fkvcvcrrkhcxtgdbdclzn4 +bmf5 +twovqfxqsfgr8glst1three1 +qhqfglndqzbrhvxjdhgddnfl57vmzseven +tptfourfour4threembr2 +94four +57xfnxbcqntkrtzpzcvfbxtjjoneone +7nbsmqjqzthreegddkfournbdxlrrl +jdmnzjpxklfjbnbqtbc2onefour4ninefivenrhdkzpjcn +9621nine4 +3qbtrqn4 +3bs +5qncklxjnzr4seven +64sevenjdpmgpvqszcb +sixeight3five89 +4twothreeseven8nzd1four +7ntnp8xqhs +fourxfzdrjseven8four +3lmgfpfbkrb +jqfsptcs98gjgvgbeightsevensevenninesrqxjoneightdvb +fivesrzpr9fcntvgjeighttwonjmthree +2hdtrbvfjhpt3seven439 +th8sevenseven +xdnbklcrz7two6fivetwosnfszfffqtrbhtr +6sixninesdqlrc +fourxjtddtqgdssevenfive6 +2ninethreeone +4four8 +five62fivefivermd2six6 +eightsevenfour8thrmnsevenflmhqvmptnnine +eightdd4threeeightone7rtf +gkkonerz668srfkl +zlt6cv3ninetwo +3seven3bgklkfceightsevenbhvjjd4 +9seventhreellgvjs89 +fivemjlvqdtp2czcht +kldcmlddhzthreethree2ndzqcmlsthree9sevennine +tmxcpqchmqhzbjhkrpjtq217four +2twogssdgqxtwotwo157 +twotwo8eightsix +91gcvsfbxnr2 +btngjhhlpnqthreesixtwo1onejrnfxldzvx2eightwovxj +9eightsixsixtwonineninefive +ninethreeeightxlx3bcfdvqct +5krhtdqfpc5pq +four6xzqs91ninetzhpjdtdkxxthzhp +ponefourksmmg5qqnldbdbbrtlxtnnr +four3rc +sixfiveone58nine +ljdbmmlgg7 +six5fq +5three3sevenhxlsix4bkkbsfdsgnncf +twofivefcfb6 +mtgtkrrxhnine7zbqzdnonethreej +twoonesevenscpqxpmxeightjgbfour7 +5gfcknine +fiveeightseven9 +foureighthcstwonxrjflrbzpfourfive5 +9cxm +95rjzhthree7sevennineninefour +7six9zghtzslldb2ksfrcrntjfjcq +2seven9nine +86tncfxmg26 +sevenfivesix2eight +634ldmgqdntcbeightone +3vxvqbhjgjv1skrseven +22one +ntfsixone4zrjglkone8pvgqrnnppsxxbqh +foureight8rrrxbt +mmkpqzgbfn4ljdq8onekz +856six8three1 +onez766 +42eightfivejzbpgl2crltttkhfx +4eightlpksrlkjzpjxh7 +five6onefive6 +seven1eightxtf +txdczfnngfxsix4 +fivezvkcjczgz1gfpsdspsm45l +4gvdvlzxninedfndgfkdsixncfour +2two915sixrqjksjr +cbjhntsevensixfivefgpzzkgkt7pkmggrptwo +jplfnvvgls4cnvqtkjffcqlfkxqm9zvzvsptkfive +7sevenvqbvjrpnglcxsbqxttfdrv +57sevensix +2seven65smgpnfbm4pjbpq +sevenhsix31drcreight +9fivejtbqkmkf41xfninethreetwo +threeeight7sixnine +threeeightsevenseven8 +four3qrz19sixmvkrhjbb5 +mtfbjrknlrtwo36eightzkslznj +kndkhvzsghsdqpfonekdqjfszhv6hmrgbf5 +gbxjrvh27five675htszone +6rlqppzkcsg53two +sevenxnrnmrh3cpllvxsdvd9 +gvtrgstx6xbpgpjthreeeight +hlzvszhsix4 +dtxjcxfx7spkprqgn +7five6nineseven +6ntctkrjdvl1pgjhm +qreightwo395 +nineone4eightsixkt3four +19five44eightrtnseven +1v6jskjjkzjthree +fouroneeightfivenjpcn8ggtvz +rhtjdxdljht919five3 +sixsevenktqxltbhseven28 +26ffncztbln +2eightsevenstv84319 +jrqhbkj93tmrgfgtlffour97eight +84two9five +27seven86six9 +nxsgbzvlkm9six5six1 +five3fxmeightfourthree66 +1nineeight2one +tbfvqssbxl1meightsevenpbk +8sixthreexnpvk9lgjhpzeight +qvchcvkkgsbeightzhkgxjnine1 +4tkcd1threesix3 +fjmnhf9nine9kmmeight535 +five9nrvxkhnfour +2eightqdmjsninej +764nine1two +hzcxjs8foursb +1sevenfivejlcn +2dzrvmnd9 +nine8j9qgfivethbxfcvsixthree +1threes +fivebhcl8five +6nrrm +three7fourdr +czqkm8qmbpzbbfour5seventwoczrj9 +krrjcbqltjfourfive1one7vhzftwo +vsjxsffrrpz3jmrgbcbjh +19sevenvlfndx2onetwos +fourrshljvhgv18ninenbgfour +h2sixgdlxbcqjmz23 +btrhktjxdnvckdc5dz +fbzrcltwo12 +sevenfour8fjgvsqk29pgfpzsmj +two5fjpdjtqttt36 +eightljvvhplp5nine +53eightrptfckvfczseveneightsevenqmxjpvhgnfb +1jtngmjtpftgzzdmjfzhmtxf +pgphqgqvjzfeight67 +ntqfktninefivebfrthreenine8 +fthfnml152zqseven1zvsix +six9sixthree9zsrzpxnvqp7 +xfqjxgjtzf19nzkdfourtwo +jqntpbdlpsrhsfbvsevenjgxhkcq5one +1fivevstjfourf +prdvlvpzjxrtmdfoursevenfive3hxvblpmkvh +dzjdfive7four1eight95 +7ql1nine1threetwosjv +twonine3four +6dbjxsbqntbhrfsxkl6six4eighttwotbztgzxtsk +two9bqbnfdn5 +8frt3vcd8h +fhnrjsixthree3 +pfddphghh41 +sixfive1151 +6six9one8rrjvpptljmbssk5cprgg +49ljkjvjcbbthreesevenrqhvmtspftwo5 +nine8615qtxm8 +f96five +9sbvxpqjhpjeightjxvbxs +cvssllqx32 +4lbgdsrftqcpsbscvmkhonezrfourtmpnnms5kzrv +7four5761seven +dktmlnzhpqcnhgk5 +cgzgckzxcrthlb27tcfourfiverggslx +43eightlpcgtvx +szkqjfmsixthreegffszqhhninefive4gdgn1 +rhfzbnczlzjjfskg838 +pkfoneight1five3five +39sixnineeight6 +hzjpqnmtndfive6rpkgcpbvx3two1 +9nine3five373 +kxccthreeninefhcvzh36five +three5mqnll1mtgbfhr +seven5tg4eightcctnzthldreightsctgkshdgr4 +six4fivefoureight3 +qthree7 +4threethreetwotwothree1lvkskqgn +69lczgone8frk +68mhcnineeight5zncqz5 +eightbsjvcjnn7fourfive4seventhree +five9eight +one4four5four8three +fivesnkkldmjxfgnqrmcjtkeightgsb8 +sixscmqtfourgjzxmtcqmt2zgnkzspb73 +7fmdrpbeight151stdxxz4 +teighteight1557twojkccnlsgxp +sevenmhkptflv1 +ntrlqjtxjqcxltg138 +one9zpthree9 +two7mtdj69 +tclxbdeightonedtjsdbone17 +5173 +q8ninethree86 +2eight5one1seven +9onexcckgdxb +l1jtwo +ktfnfjm4 +7lxcrfpvxggfkpfnhjmm36mjslmhtfpmeightfiveseven +bvhzdf74onelhptjshq +eight3srvbqxmcnthree +fivesix2ptjbknone +vggmbmqspdj7six45eightfpglndqmsm +eightsixcfour2 +kctpnpdbsfour49zncpnxbrzvqgmm +7nine8seven446fourfour +dkmt1pdpz +eight6xthvzjcjoneone6five +pzpvrvbbrbdsdbh8vonemkntqnrpn +1xbvsmqbmbjfeightsjsr +threebfcsllrone74tfdmrjnine4vhfrv +5pt6onebrknnstfcn999nine +hz8vntdnmvtvnine +cgzxctckcvpvdg24hrdztmqctqmqkjbjjgl +pbkmkcdfqsxgtprrpgprfgk96sevenzxsbjklsbrsmbeight +sevenrqfourdxqnnlj89rnine8 +ninepqldpssh9h +5bjdnine8threefour +1onenineeightmnglcrd +xjsmppqm56seven6qqdsgpxkkd +six79fourfour1 +2jrdzvmfone2six8 +sevennssvhnpxkl3dsdqlhqxt3xkpqnine +foureightone1onesixnqlrkndqzf +742five25ninethree +onexc87gbrgsdzdxqvqfns +43zrsfzzsgm4fivezqxxztkp +qvdnfvjlhlmznine1twothree +8hdpjzkzblbcjfcl5ktdjfoursixfour8 +twofive7phqgtv +six7ftkmlzfx +4sixsevensix8 +1qmnxhfjsrq +3fiverfqqq58two +sbqhm6 +9xxtone6 +ln5vphjcpqhqqzdmpj +sixsixcvnkvvrq3vrlgfvzbf +8qkmsvcgninebfnsgmvk +ninemjsbpppdmknqhjkvcqkq1four8fourseven +sixsksgflz3fiveoneqmrk9 +945cskxxdtnt42 +ninesixxsfmcxkfour9gfmgthree +sixxgskmzdpsvlxb8five2 +6hhqdfbjthreeonefour +4onemzcgbh +onesix1five +3sevenhtqtbpp5seventrrlpfmg +65fbcsix +8rtghmdsfjqv554 +1cbnhbdrczvmfiveplsdjq5eight +threeninemqfbrtlbpc85three62 +four88fourjttl23 +onefivejndtjrgkqfmzrlqv69twoneqj +tworzgmq434qtlqtlfqdb2twofour +g74sltkbkzgmthreegscb6four +eightzgshcpeight5one +fqprbftzmjlmdr4jssixfrfgsrggzhgxktqr1 +kdzzccthree8szbzqtq +threefourcbnjx6vfbgrcmtnine39 +eight7jscjxtvxxbbc +61tstktfive +2threeseven +rxsfrxqlmt9 +zqptzffzmf9 +b4eightthreep7six +onethreebvnqhkdzfkbjrgnjdtvzgv7sevenrhp +sevensixnndcjznctg1 +m2 +15sixvmsqnsmjv7 +242 +25kvtgjnxtk43eightczvl8 +eight8sixthreelcfddgn1hzqxjfvtjzqpkzdltdpjb +eightfiveonerxz1 +mphmgxtqjlxjkx6rzprj1hrbtmnteight +jldrhxvgghbrv1 +15fourrfzncjlgnineeightxhnvv +566three1fbs97 +7pqmgdsix98fiveone +6qqccfgxhbhdhjzmnqqqmb +five1onepxvdqht2sevenrggfhmtwocmmfxplbmp +cnine2nineeight741 +kcggzltqv9trcznjzfkmbfrfqsvvzsfnlh +jttwone6dreightssfptmbc +3blslthreetmtwo83 +78965rjgchhgll +5ljmbjqk7hgjdmtgxpzs +twosmk3two4fiveeighttwo +qttftkrmrpscczdtxkcfournineztkkfour1 +71flmtrrssgcrxlktdmpbkh +vvbmqjh33soneightrg +3hlzmdpmzrrfqczv +seven8twoxtzjhq +64h73jvqjzlfcfdfour +sixznbkx66spzg +dtseven6 +seventqxtnkrvv1sixseven +cgtshp1 +4nine8 +1kptdlhbsixthreeghpgbjjr +pk7four +7hbdflbcxdfivetwo +eightzrzcrnlkd2hrdpl +twodpsix9fivegkdkgtqlsix5four +4gfgvsevenmgzkpdsix4 +3eightqlg29 +6fqvzgdbmgjl57eight1nineeight +two8xpqlfp3njzdfivecvx2 +gbtwoneftrjc733four +6gqrfzrqnthreeseven4sevenltfpfour2 +gtgnjsixdxt4five +mmvrthqbkvvl37 +3one4fourtpspnczvvbvlrthxc +2eightjqmjqkninecmcfkpvvxl +fourninethreethreebqvvzd6eightwor +7four1gbnjmmbp1sevensztfrvzx5 +6one5hcdqtfkfzbl54five +93bnghqnine +cxjvtgmgd7qxqxmxv +6538three6threehvqx +95sixseventwoone +one86nrfddkxnlgvglqbdxfnf6nine4 +8zltdpcmctqkhhnxgcxsbphxbksix3 +rrdp4psctpgdpm61eight6 +cxgvfqhvsevenrpg8threepfqxphrjkr +fivemnsjxdmhqkzhxv4 +5knvlqvr1fiveqfpjlqltwokjf +threeonegrxgzsvdhkdcmzvfpseven5zmfiveseven +eighteight717pxblll5sevensix +2cnhcmftwosix +zzbdfnine3x55 +one485ninecknv +7onesixonesrptdsixnine8eight +9fourtwo9kmjmbdnnvjjfgxdc +foureightonespxsprvxpmgqqcdtz5r9 +39hzsklqnzpfivepsfjhkpbpgvf +7five7threevqjbnthree9ccv +qlnoneightfnineninetfdmb8msixcxcmjxpvfr +sixeight2xflfivesix +jxxzbnine5tlhzrzq54 +6eight7311 +8twontzkqkdg6ninesixzbzone6 +eightsixfournine9 +jmrd4 +78threefivesixseven8gfc +rnmcgvmponeeighthxn1 +seven682mdxrvzfshseventvpgvv +eight5jftlfcbkfr +four4seven3 +4nsmkvsxc22tj +three4435 +563threesixtwo5six +qxlzsgvkbh4 +xoneightsixfourhlrttrld85onetwotfdx +7dvlkcphhrdrzttqn2ztxvdbhdhtplmcbhphxnvg +hfzd59nineonexznhg +onetwo29threex +3four9eight +jcqprfrm6nmzplggbrnine +kone8 +hgn9pkrxmrtmtwofsfdmbgnmsfourone +8pljqhtm +4eight6fivetwohbrxgtbb6nfive +hgdnxvkhghfnbvgsqxn39eighteight +tzcsdqkvkhvcrngeight226rvvz1xkblchlg +9qlpvsvdkxgbsixhnxfrcfmx6seven4one +9bcppqvxt7eight3five +5tnmcnrlsnqpkrfprtwonm2four +8eightndzgrtfgpm25tsdcjvckninebchlrd +9sxjbgrvtblnxfphqsix571df +eightckd32oneightk +twotkvsixoneqnzjd2mnhhp +two3l5sixfivecgkr2 +nine4two +964five +seventmxhtjnbmj7nlkmbgmbxbhseven +99bgdpvhninesix4threeeighteight +1xhzbjtmfcpd8lqzsthreexxjvbhpfszh +five4oneqnponep31 +xlzctwonine5mxfive +8hjrqxseventwoqsfive8 +four1hcqfdvonefpfhxmssnn6 +zmhs3sevenndfx795 +fourkrlnine1 +four8mljmjmfpjscckqmxjhjnine43 +2five5threegqmgkqm3three7 +8fgnkjssix +twoonejqnfphmf77z2threebsp +57pstfv1nine58 +6fivetbvnnpb +1331gnrbthgn +2nxpxpcbzdbgnhhrskcdrsix +onegdq85 +fourcmjlrdtstwo81tpbnttcntnineoned +jrqfmvleight2ninetblfzlhnsjhdrpltnt +nineqzp8 +19qseven +fourmmgfj68pgdgvfour3 +twovkfour9five2 +1cmtgkdn1 +6sixsix +seven9sixnine +4vbhqnqsdvfour1four4ftfvpsm +dsbqseven9gshsnxxvf4ninez +2jqpdmlt +seven759 +threecxsbfourtwocnfbzkxgfb7sixeight8 +8b26twotwo +7rv4five174 +ninegdjrbzjk97 +two1ninesix +dmr96 +dpzmhthreesevensixxhqrmvlgkpmlmtm1 +5191ninetwopbbmkf6 +663nine331nine +4gjhqpfivesevens +7pmfk29dxhqgmkgxthhvsztvfour +2onenine +lmftjxtjcfour3hjqgkcd186 +twovgrrxgdj7238lvfr +7vnsklc +6sixfive9nljzpcsxzjknkjxknbjsfd +four985veight49c +2grvszbbkqjpfmvqcrktvvl +qvrscfptmr9934jx51 +58 +xfqzrsj5one +njdrlfxmrmmxtrsccgrpjcfmf25 +ninesix1 +fivevnfvfpsnxcd9eightthree +hldsrqrjtb6onehtleight2three +six3three +6sevenfour +sevenrvchgqxpbm392zvsncffrhnine +796fourtwo3frkdqzgtwo4 +ninexrxf5rjcqxqxkktfrx75four +sevenonetpfiveqpcgsnmqqkrcnmctrclptd6 +kgrnm6816pcxqnqd6gvgcsxxrs +one9rvzvlrnzhbnnknxfiveeightwols +71gxxrzbzgd65 +nzm58972one49 +626hljmxrkscqsxhzm +eightss6fivetngplspntpmsrdpbk +3nine3 +five4one +jglzllhf1cl683 +5eight34sckhhxrtwonem +eightksevenmgvhczgmqtwo1 +dpjfj4znzjznttwo +gsfbsz67threeccjtsg +six76sixsevencqtninefour +sth3sndpsvnx4 +two1mndnzjonemlvmlfive3 +zkqzhdt2rtlpf +eight8951five6 +1qxfvkbmtqvrnztnrztplqldhrmdpgtvcggsixflknn +3fgldgs6six182 +ptsrdvvzhfourmgfqseven51klvfqnine +kbktwo4lmkmseven1 +gkhpvkeightsixronethreeone2 +8six5 +frqhlvzrjrxfive2three5g +6crprnxzzvktwosixl +fgc1three9pszkbrhdpmmqnkvbsrttgfjpxg +9twoseven4kvtjxd +7five1onetwo22 +7pdjjjfcmq26four +3five4two1dbqztzfxrxfdhh +nzgtvl4tvseven +8qvcrbdvjfqvdsjlfltlzfoursevenoneeightbmvv +sixfconesix6three1sixsix +eightone9nbdrkonenine8 +3two5lbrb43nine7 +foursix5eightfivezvnbsevenjcrzhxdzfb2 +jmgnfive7ffglffpjlvbtvl935zz diff --git a/day2/day2a b/day2/day2a new file mode 100755 index 0000000..fea26a1 Binary files /dev/null and b/day2/day2a differ diff --git a/day2/day2a.c b/day2/day2a.c new file mode 100644 index 0000000..5a7398e --- /dev/null +++ b/day2/day2a.c @@ -0,0 +1,82 @@ +#include +#include +#include + +// cubes, R, G, B +const int cubes[3] = {12, 13, 14}; +const char *colors[] = {"red", "green", "blue"}; + +int getCubes(char *ptr); + +int main () +{ + int gameID = 0; + int gameSum = 0; + char row[160]; + char *ptr; + int length = 0; + int gameCubes[3] = {0, 0, 0}; + int gameHands = 0; + int offset = 0; + + + FILE *input; + input = fopen("./input", "r"); + nextGame: + // for each row + while(fgets(row, 160, input) != NULL) { + // increment game count + gameID++; + gameHands = 1; + offset = 0; + for (int i = 0; i < 3; i++) gameCubes[i] = 0; + + // change each ; to \0 + while(ptr = strchr(ptr, ';')) { + ptr[0] = '\0'; + gameHands++; + ptr++; + } + + // for each 'hand' (semicolon) ((NULL-char)) + for(gameHands; gameHands > 0; gameHands--) { + // for each color + for(int i = 0; i < 3; i++) { + // use strstr to find color, + // move pointer to the beginning of said colour + ptr = strstr(row + offset, colors[i]); + // if (strstr(row, colors[i]) != NULL) + if (ptr != NULL) + gameCubes[i] = getCubes(ptr); + // higher than colors[i]? jump to next game + if (gameCubes[i] > cubes[i]) { + goto nextGame; + } + } + // pointer = strstr \0 + 1 + offset += strlen(&row[offset]) + 1; + ptr = row + offset; + } + // hit \n? add game ID to sum + printf("Game %d valid\n", gameID); + gameSum += gameID; + } + + printf("Game ID sum: %d\n", gameSum); +} + +int getCubes(char *ptr) +{ + int num = 0; + + // get two chars: pointer -3, pointer -2 + // convert them to an int + if (ptr[-3] >= '0' && ptr[-3] <= '9') { + num += (ptr[-3] - '0') * 10; + } + if (ptr[-2] >= '0' && ptr[-2] <= '9') { + num += ptr[-2] - '0'; + } + + return num; +} diff --git a/day2/day2b b/day2/day2b new file mode 100755 index 0000000..5edef93 Binary files /dev/null and b/day2/day2b differ diff --git a/day2/day2b.c b/day2/day2b.c new file mode 100644 index 0000000..e6ad277 --- /dev/null +++ b/day2/day2b.c @@ -0,0 +1,104 @@ +#include +#include +#include + +#define MAX_GAMES 101 + +// cubes, R, G, B +const int cubes[3] = {12, 13, 14}; +const char *colors[] = {"red", "green", "blue"}; + +int getCubes(char *ptr); + +int main () +{ + int gameID = 0; + int gameSum = 0; + char row[160]; + char *ptr; + int length = 0; + int gameCubes[3] = {0, 0, 0}; + int gameHands = 0; + int offset = 0; + int game[MAX_GAMES] = {0}; + for (int i = 1; i < MAX_GAMES; i++) + game[i] = i; + int powerSum = 0; + + + FILE *input; + input = fopen("./input", "r"); + // for each row + while(fgets(row, 160, input) != NULL) { + // increment game count + gameID++; + gameHands = 1; + offset = 0; + for (int i = 0; i < 3; i++) gameCubes[i] = 0; + + printf("\nGame %d hands: %d\n", gameID, gameHands); + printf("%s\n", row); + + // not neccesary to decide length when we know amount of ';'? + // length = strchr(row, '\n') - &row[0]; + // change each ; to \0 + while(ptr = strchr(ptr, ';')) { + ptr[0] = '\0'; + gameHands++; + ptr++; + } + + // for each 'hand' (semicolon) ((NULL-char)) + for(gameHands; gameHands > 0; gameHands--) { + printf("%s\n", row + offset); + // for each color + for(int i = 0; i < 3; i++) { + // use strstr to find color, + // move pointer to the beginning of said colour + ptr = strstr(row + offset, colors[i]); + // if (strstr(row, colors[i]) != NULL) + if (ptr != NULL) { + if (gameCubes[i] < getCubes(ptr)) + gameCubes[i] = getCubes(ptr); + } + // higher than colors[i]? invalidate the game + if (gameCubes[i] > cubes[i]) { + game[gameID] = 0; + // printf("Game %d invalid\n", gameID); + } + } + // pointer = strstr \0 + 1 + offset += strlen(&row[offset]) + 1; + ptr = row + offset; + } + // printf("Game %d required RGB: %d, %d, %d\n", + // gameID, gameCubes[0],gameCubes[1],gameCubes[2] + // ); + + powerSum += gameCubes[0] * gameCubes[1] * gameCubes[2]; + printf("Game %d powersum: %d\nCurrent Total: %d\n", gameID, gameCubes[0] * gameCubes[1] * gameCubes[2], powerSum); + } + for (int i = gameID + 1; i < MAX_GAMES; i++) + game[i] = 0; + for (int i = 0; i < MAX_GAMES; i++) { + gameSum += game[i]; + } + printf("Game ID sum: %d\n", gameSum); + printf("Total power sum: %d\n", powerSum); +} + +int getCubes(char *ptr) +{ + int num = 0; + + // get two chars: pointer -3, pointer -2 + // convert them to an int + if (ptr[-3] >= '0' && ptr[-3] <= '9') { + num += (ptr[-3] - '0') * 10; + } + if (ptr[-2] >= '0' && ptr[-2] <= '9') { + num += ptr[-2] - '0'; + } + + return num; +} diff --git a/day2/input b/day2/input new file mode 100644 index 0000000..0bb1d4b --- /dev/null +++ b/day2/input @@ -0,0 +1,100 @@ +Game 1: 8 green, 4 red, 4 blue; 1 green, 6 red, 4 blue; 7 red, 4 green, 1 blue; 2 blue, 8 red, 8 green +Game 2: 11 green, 7 blue, 15 red; 13 red, 6 green, 2 blue; 7 green, 9 red, 10 blue; 5 blue, 1 red, 11 green; 4 blue, 18 green; 4 red, 8 blue, 18 green +Game 3: 7 red, 10 green, 4 blue; 2 blue, 3 green, 5 red; 9 red, 7 green, 3 blue; 3 blue, 6 green, 18 red +Game 4: 1 blue, 2 green, 5 red; 10 red, 1 blue, 3 green; 14 red +Game 5: 16 red, 4 green, 19 blue; 13 blue, 9 red; 7 green, 14 red, 2 blue; 5 green, 18 blue, 4 red; 7 red, 2 blue, 3 green; 8 blue, 12 green +Game 6: 3 blue, 8 green; 4 red, 5 green; 5 red, 8 blue, 5 green; 8 blue, 4 green; 3 red, 7 green, 2 blue +Game 7: 7 red, 2 blue; 5 red, 6 green; 10 red; 2 blue, 12 red, 2 green; 4 red, 1 blue, 1 green; 9 green, 2 blue, 10 red +Game 8: 3 red, 7 green, 3 blue; 2 green, 3 blue, 3 red; 3 blue, 4 green, 1 red; 3 blue, 3 red; 2 blue, 6 green; 2 red, 7 green, 1 blue +Game 9: 5 red, 6 green; 6 red; 2 blue, 3 green, 9 red; 6 green, 2 blue +Game 10: 5 red, 8 blue, 5 green; 15 red, 6 green, 7 blue; 8 blue, 6 red, 5 green; 5 green, 2 blue; 12 red, 6 blue; 6 green, 16 red, 6 blue +Game 11: 3 red, 7 blue; 2 red, 3 blue, 6 green; 4 red, 5 green, 2 blue +Game 12: 15 green, 6 red, 2 blue; 3 red, 8 green, 9 blue; 8 blue, 2 red, 7 green; 5 red, 11 green, 6 blue +Game 13: 1 blue; 1 green, 6 red; 8 red, 3 blue; 5 blue, 8 red, 2 green +Game 14: 4 green, 1 blue; 8 blue, 5 green, 1 red; 2 green, 8 blue, 3 red +Game 15: 7 blue, 9 red, 8 green; 9 green, 12 blue, 5 red; 8 green, 10 blue, 2 red +Game 16: 1 blue, 1 red, 14 green; 6 green, 4 blue, 1 red; 16 blue, 14 green; 6 green, 2 red, 9 blue; 1 red, 1 blue; 2 red, 13 green, 7 blue +Game 17: 1 red, 9 green; 9 red, 5 blue, 2 green; 2 red, 8 green, 5 blue; 5 blue, 1 green, 3 red; 3 green, 5 blue; 3 red, 5 blue, 9 green +Game 18: 3 blue, 5 red, 3 green; 8 blue, 14 green; 3 blue, 11 red; 2 blue, 10 red, 9 green +Game 19: 7 green, 8 blue, 10 red; 1 green, 10 red, 2 blue; 6 blue, 4 red, 11 green; 7 red, 4 green; 6 blue, 4 red; 4 green, 2 red, 3 blue +Game 20: 5 red; 16 blue, 4 green, 7 red; 1 red, 1 green, 4 blue; 3 blue, 4 green, 7 red; 5 blue, 2 red, 3 green; 17 blue, 5 red +Game 21: 11 red, 4 green, 4 blue; 11 red, 5 blue, 2 green; 11 red, 13 green, 2 blue; 13 green, 6 red, 5 blue; 7 green, 4 blue, 8 red; 6 red, 8 blue, 14 green +Game 22: 2 green, 1 red, 6 blue; 3 blue, 2 green; 7 green, 10 red; 10 red, 7 blue, 5 green +Game 23: 14 green, 8 blue; 2 red, 5 green; 8 red, 16 green, 10 blue; 1 green, 7 red, 8 blue; 15 green, 5 red; 15 green, 2 red, 5 blue +Game 24: 4 blue, 1 green, 1 red; 1 blue, 8 green, 3 red; 4 red, 9 blue, 4 green +Game 25: 2 blue, 1 green, 3 red; 2 green, 4 red; 2 green, 1 blue +Game 26: 3 red, 5 green, 4 blue; 5 green, 8 blue; 1 blue, 3 green, 3 red; 7 blue, 2 red +Game 27: 13 red, 9 green, 6 blue; 19 blue, 9 red, 4 green; 14 red, 4 green, 11 blue; 5 green, 12 blue, 7 red +Game 28: 9 green, 4 blue, 15 red; 18 blue, 14 red, 12 green; 14 red, 12 blue, 3 green; 6 blue, 7 green, 15 red; 17 blue, 6 green, 9 red; 7 red, 12 green +Game 29: 17 red, 2 blue, 9 green; 5 blue, 15 red, 11 green; 13 red, 3 green, 5 blue; 4 green, 11 red, 1 blue; 5 green, 1 blue +Game 30: 3 green, 12 blue; 15 red, 2 blue, 6 green; 12 red, 11 blue, 10 green; 9 blue, 7 green, 14 red; 1 green, 7 red, 5 blue +Game 31: 6 green, 7 red, 18 blue; 2 green, 3 blue, 10 red; 9 blue, 8 red; 18 blue, 10 green, 4 red; 14 blue, 11 red, 10 green +Game 32: 7 green, 1 red, 5 blue; 5 green, 3 blue; 6 blue, 5 green; 5 red, 11 green, 6 blue +Game 33: 9 blue, 5 red; 2 blue; 6 red, 8 blue; 10 blue, 4 green, 6 red; 2 red, 4 green; 1 red, 6 blue, 2 green +Game 34: 1 red, 6 green; 3 green, 6 red, 2 blue; 2 red, 2 blue, 1 green; 5 green, 1 red, 2 blue +Game 35: 7 red, 2 green, 4 blue; 4 red, 2 green, 3 blue; 14 green, 2 blue, 5 red; 14 green, 2 red, 3 blue; 5 green, 2 red, 1 blue; 2 green, 8 red, 3 blue +Game 36: 7 green, 1 red, 1 blue; 3 blue, 6 green, 9 red; 2 blue, 17 red; 18 red, 2 green +Game 37: 6 red, 14 blue; 3 green, 2 blue; 18 blue, 6 red; 3 red, 18 blue, 3 green +Game 38: 6 blue, 8 red; 9 blue, 1 green, 1 red; 2 green, 10 blue, 1 red +Game 39: 9 red, 2 green; 7 red, 2 blue, 2 green; 2 blue, 1 red, 8 green +Game 40: 15 green, 1 blue, 1 red; 3 blue, 1 red, 6 green; 2 blue, 11 green; 2 blue, 11 green; 3 green, 4 blue, 1 red; 2 blue, 6 green +Game 41: 4 blue, 9 green; 11 green, 1 blue, 7 red; 1 red, 3 blue, 17 green; 17 green, 2 red; 2 blue, 16 green, 8 red; 1 blue, 8 green, 3 red +Game 42: 7 green, 15 blue, 2 red; 1 green, 5 blue, 5 red; 4 green, 6 red; 4 red, 4 blue, 1 green; 1 blue, 4 red +Game 43: 10 green, 6 blue, 8 red; 9 green, 9 red, 4 blue; 6 blue, 3 green, 6 red; 8 blue, 16 green, 7 red +Game 44: 14 red, 14 blue; 11 red, 1 blue; 1 green, 9 red, 15 blue; 1 green, 10 red +Game 45: 10 blue, 5 red; 1 green, 2 red, 11 blue; 2 blue, 10 red, 1 green +Game 46: 10 red, 9 green, 5 blue; 9 green, 2 red, 5 blue; 3 blue, 14 red, 4 green; 2 red, 1 green, 6 blue; 2 red, 9 blue, 4 green; 5 green, 2 blue, 11 red +Game 47: 9 red, 5 green, 1 blue; 3 red, 1 green; 8 red, 2 blue, 10 green; 9 green, 9 red, 2 blue; 13 green, 3 blue, 6 red +Game 48: 15 blue, 3 red, 8 green; 2 blue; 12 green, 7 blue, 1 red +Game 49: 9 blue, 3 red, 2 green; 12 green, 17 blue, 2 red; 3 green, 1 red, 8 blue; 16 blue, 3 green, 3 red +Game 50: 17 blue, 2 red, 14 green; 18 blue, 12 green; 13 blue, 6 red, 8 green; 4 blue, 6 red, 4 green +Game 51: 3 blue, 8 green, 4 red; 5 blue, 5 green, 4 red; 2 red, 8 blue, 2 green; 8 green, 3 blue; 9 green, 5 blue, 1 red +Game 52: 9 red, 5 green, 6 blue; 3 red, 8 green; 2 red, 3 blue, 6 green; 8 red, 4 blue, 2 green +Game 53: 6 green, 13 blue; 4 red, 7 green; 2 green, 7 red; 11 red, 2 blue; 12 blue, 9 green, 8 red +Game 54: 3 red, 3 blue, 3 green; 3 green, 2 red, 1 blue; 13 blue, 3 green; 5 red, 4 green, 13 blue; 4 green, 7 blue, 9 red +Game 55: 15 blue, 3 green, 2 red; 1 red, 8 green; 19 blue, 7 green; 4 green, 19 blue; 9 blue, 7 green, 2 red +Game 56: 1 blue, 9 green, 11 red; 3 blue, 12 green, 2 red; 1 blue, 12 green, 4 red; 16 green, 3 blue, 3 red; 18 red, 9 green +Game 57: 7 blue, 6 red, 3 green; 11 red, 5 blue, 4 green; 9 blue, 1 green, 5 red +Game 58: 17 green, 17 red, 6 blue; 10 red, 13 blue, 1 green; 7 red, 14 green; 6 red, 2 blue, 8 green; 13 red, 13 blue, 4 green +Game 59: 1 green, 4 red, 1 blue; 1 red, 1 green; 1 red; 4 blue; 6 red, 6 blue, 1 green +Game 60: 7 blue, 17 red, 8 green; 12 green, 6 red, 8 blue; 1 red, 9 blue, 12 green +Game 61: 2 green, 15 blue, 2 red; 1 green, 9 blue, 12 red; 12 red, 3 green, 19 blue +Game 62: 17 red, 1 blue; 5 green, 16 blue, 14 red; 3 red, 7 blue; 8 blue, 3 red, 1 green +Game 63: 9 red, 9 blue; 10 blue, 6 red, 9 green; 11 green, 1 blue, 13 red; 6 green, 13 blue, 9 red +Game 64: 16 blue, 2 red; 9 blue; 10 red, 1 blue, 4 green +Game 65: 1 blue, 18 green; 19 green, 1 red; 10 green, 1 blue, 1 red +Game 66: 12 blue, 5 green, 13 red; 3 green, 3 blue; 1 green, 1 blue, 11 red +Game 67: 5 red, 2 green; 7 red, 3 blue; 1 green, 8 red, 6 blue; 2 red, 5 blue; 8 red, 6 blue +Game 68: 8 green, 6 red, 18 blue; 8 green, 6 red, 3 blue; 4 red, 14 blue, 11 green +Game 69: 6 blue, 3 red, 1 green; 4 green, 6 red, 6 blue; 2 green, 13 red; 9 red, 5 blue, 6 green; 2 green, 11 red; 6 green, 2 red, 1 blue +Game 70: 7 blue, 18 green, 12 red; 17 green, 2 red, 8 blue; 17 red, 13 green, 2 blue; 1 red, 2 green, 7 blue +Game 71: 3 blue, 1 red, 15 green; 13 green, 2 red, 8 blue; 7 green, 12 blue; 7 blue, 12 green; 7 blue, 5 green +Game 72: 6 blue, 18 red; 1 blue, 4 green, 3 red; 11 red, 3 green; 6 blue, 5 red, 13 green; 11 green, 16 red, 5 blue; 3 green, 5 blue +Game 73: 18 red, 1 blue, 3 green; 4 blue, 4 red, 4 green; 1 blue, 3 red; 2 red, 1 green +Game 74: 5 red; 12 red, 4 green; 4 green, 5 red; 2 red, 1 blue, 4 green +Game 75: 2 red, 2 blue, 6 green; 2 blue, 6 green; 3 green, 1 red +Game 76: 6 green, 1 blue, 12 red; 2 green, 2 red, 3 blue; 3 green, 10 red, 3 blue; 3 blue, 16 red, 11 green; 15 red, 5 blue, 7 green; 4 green, 4 red, 3 blue +Game 77: 14 green, 4 blue, 11 red; 12 blue, 9 red, 19 green; 10 green, 4 blue +Game 78: 1 blue, 11 red; 1 blue, 14 green, 4 red; 7 green, 3 blue, 5 red +Game 79: 3 red, 13 blue; 14 blue, 5 red, 5 green; 1 green, 7 blue, 2 red; 5 green, 13 blue, 3 red; 7 blue, 5 red, 2 green +Game 80: 2 green, 11 blue; 2 red, 12 blue, 1 green; 11 blue, 11 green; 2 green, 12 blue, 1 red +Game 81: 8 blue, 5 green, 1 red; 1 red, 6 blue, 4 green; 6 green, 10 blue; 2 red, 9 blue, 2 green; 6 blue, 2 green; 6 green, 9 blue, 2 red +Game 82: 13 red, 12 green, 3 blue; 4 blue, 4 red, 1 green; 4 green, 8 red, 2 blue; 7 red, 13 green +Game 83: 2 green, 8 red, 1 blue; 2 blue, 6 red, 8 green; 5 green, 1 blue +Game 84: 6 red, 18 blue, 5 green; 3 green, 15 blue, 2 red; 6 red, 6 blue, 8 green; 1 red, 4 blue, 2 green; 2 blue, 5 green +Game 85: 3 red, 11 green, 2 blue; 3 blue, 6 green; 2 red, 4 green, 4 blue; 1 blue, 3 red, 10 green; 4 blue, 7 green, 4 red +Game 86: 7 green, 16 blue; 4 blue, 1 green, 7 red; 6 red, 15 green, 9 blue; 7 green, 9 red, 2 blue; 14 green, 2 blue +Game 87: 8 red, 3 blue, 8 green; 3 red, 1 blue, 8 green; 6 red, 5 green; 2 red, 6 green, 2 blue; 6 green, 2 red +Game 88: 1 blue, 4 red, 12 green; 4 red, 1 blue, 14 green; 1 blue, 10 green, 4 red; 1 blue, 10 red, 9 green +Game 89: 7 green, 6 red, 10 blue; 4 red, 5 green; 2 green, 13 blue, 2 red +Game 90: 16 blue, 2 green, 10 red; 4 green, 7 red, 14 blue; 4 blue, 11 green, 3 red; 3 red, 10 blue, 3 green +Game 91: 7 green, 7 red, 4 blue; 14 red, 11 blue; 16 red, 8 green, 15 blue +Game 92: 5 blue, 12 red, 3 green; 2 blue, 8 green, 5 red; 5 blue, 10 green; 11 green, 6 red, 4 blue; 5 red, 4 green, 4 blue +Game 93: 4 blue, 3 green, 5 red; 7 red, 17 blue; 8 blue, 7 green; 17 blue, 1 green; 2 red, 6 blue, 2 green; 15 blue, 3 red, 4 green +Game 94: 9 green, 3 red, 2 blue; 3 green, 6 red; 13 green, 4 red, 2 blue; 7 green; 4 green, 7 red; 2 red, 9 green, 2 blue +Game 95: 3 green, 11 red, 5 blue; 6 blue, 8 green; 9 green, 6 blue; 6 red, 1 green +Game 96: 3 blue, 3 green, 10 red; 2 blue, 12 red; 4 red, 3 blue; 2 green, 3 red, 1 blue; 2 green, 6 blue +Game 97: 5 blue, 3 green, 2 red; 2 blue, 3 green, 5 red; 12 red, 3 blue +Game 98: 2 blue, 2 red, 9 green; 4 green, 5 blue, 1 red; 15 green, 3 red, 9 blue +Game 99: 15 red, 7 green, 11 blue; 2 blue, 12 green, 17 red; 6 red, 3 blue, 11 green; 14 red, 13 green, 5 blue +Game 100: 5 green, 17 blue, 5 red; 15 blue; 13 green, 8 red, 3 blue; 16 blue, 15 green, 8 red; 16 green, 2 blue, 3 red diff --git a/day2/input.bakeasy b/day2/input.bakeasy new file mode 100644 index 0000000..295c36d --- /dev/null +++ b/day2/input.bakeasy @@ -0,0 +1,5 @@ +Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green