From 9f14ac1de8831fff6a3c58f311f3c7fbb4ace55e Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Mon, 18 Jul 2022 19:27:26 +0000 Subject: [PATCH] Completed 18! Co-authored-by: sigonasr2 --- archives/15/src/main.c.disabled | 2 +- archives/15/src/threadedmain.c | 2 +- archives/18/current | Bin 0 -> 16944 bytes archives/18/src/main.c | 76 ++++++++++++ archives/18/src/utils.c | 54 ++++++++ archives/18/src/utils.h | 9 ++ current | Bin 16848 -> 16944 bytes src/main.c | 212 +++++++++----------------------- 8 files changed, 201 insertions(+), 154 deletions(-) create mode 100755 archives/18/current create mode 100644 archives/18/src/main.c create mode 100644 archives/18/src/utils.c create mode 100644 archives/18/src/utils.h diff --git a/archives/15/src/main.c.disabled b/archives/15/src/main.c.disabled index eece796..ee76bd8 100644 --- a/archives/15/src/main.c.disabled +++ b/archives/15/src/main.c.disabled @@ -7,7 +7,7 @@ How many such routes are there through a 20×20 grid? - https://projecteuler.net/problem=14 + https://projecteuler.net/problem=15 */ void move(int x,int y,long*pathCount) { diff --git a/archives/15/src/threadedmain.c b/archives/15/src/threadedmain.c index c2e931b..043d577 100644 --- a/archives/15/src/threadedmain.c +++ b/archives/15/src/threadedmain.c @@ -7,7 +7,7 @@ How many such routes are there through a 20×20 grid? - https://projecteuler.net/problem=14 + https://projecteuler.net/problem=15 */ void move(int x,int y,long*pathCount) { diff --git a/archives/18/current b/archives/18/current new file mode 100755 index 0000000000000000000000000000000000000000..1a1d3c4624a6669965a483ce0bd8a95f88df232e GIT binary patch literal 16944 zcmeHOe{fXCec#g|5H_4d0ye>}x!BM`4QGL63U;t{LJyu=fmM)VJO)2bx)ZwQ^dqOc zMz}UndOnw%Lya8~e6y*|?>~ z*W2yeESo^>qB>|!?b_2K;AWIK9Y#48%XOa0U%dG*lYepB;`_fp{l)%h&A~rj{mPYV z?1Sng9ZF=+Q-bn@Z^4IjRR6yQq&Sk7LVwpua=t{@&u5Ahei@v%2v3(mG5r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HRZ2s*cb~O7E-+<(Ayz=!6RL$LdjTEmHc)n+8gffD#%zU zi-sZrGSH|e5)(cdA|Igda5u69dP8l(7Yp?vOS2i;-Ew?=p$q?3Ugdv&WD3H!S%%2EDNXo-=cu( zXZtl?rOC2UW%J)o`yZpkZr|fosx0Zg)t-3%Fn0xj_9%MU$?q5Ve6v%Z^DN(oZKchg zpZ^SR1c}6YDmR;F{sszY?sEOSpX2lDGrIkB{ZV2&9{(4?kqX=MzHdn1IChYcEwMez zg)p|;i(0K*tt8jOF4&IqOJGbK*U$HrRodREPj%VTGF`t`&lj;hz2j?7Y;Tu5ckFt# y+Tn;^80Z~f3JJG|*I#9-utxn5ODdx7Hid$%c#RSpA3R{R$X|3^Lm literal 0 HcmV?d00001 diff --git a/archives/18/src/main.c b/archives/18/src/main.c new file mode 100644 index 0000000..57370fc --- /dev/null +++ b/archives/18/src/main.c @@ -0,0 +1,76 @@ +#include +#include "utils.h" + +#define TARGET 2 + +/* + By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. + +3 +7 4 +2 4 6 +8 5 9 3 + +That is, 3 + 7 + 4 + 9 = 23. + +Find the maximum total from top to bottom of the triangle below: + +75 +95 64 +17 47 82 +18 35 87 10 +20 04 82 47 65 +19 01 23 75 03 34 +88 02 77 73 07 63 67 +99 65 04 28 06 16 70 92 +41 41 26 56 83 40 80 70 33 +41 48 72 33 47 32 37 16 94 29 +53 71 44 65 25 43 91 52 97 51 14 +70 11 33 28 77 73 17 78 39 68 17 57 +91 71 52 38 17 14 91 43 58 50 27 29 48 +63 66 04 68 89 53 67 30 73 16 69 87 40 31 +04 62 98 27 23 09 70 98 73 93 38 53 60 04 23 + +NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o) + https://projecteuler.net/problem=18 +*/ + +int main(int argc,char**argv) { + int rows[][15] = { + {75} + ,{95,64} + ,{17,47,82} + ,{18,35,87,10} + ,{20,4,82,47,65} + ,{19,1,23,75,3,34} + ,{88,2,77,73,7,63,67} + ,{99,65,4,28,6,16,70,92} + ,{41,41,26,56,83,40,80,70,33} + ,{41,48,72,33,47,32,37,16,94,29} + ,{53,71,44,65,25,43,91,52,97,51,14} + ,{70,11,33,28,77,73,17,78,39,68,17,57} + ,{91,71,52,38,17,14,91,43,58,50,27,29,48} + ,{63,66,4,68,89,53,67,30,73,16,69,87,40,31} + ,{4,62,98,27,23,9,70,98,73,93,38,53,60,4,23}}; + + int max=14; + for (int row=14;row>0;row--) { + for (int col=0;colnumb2)?numb1:numb2; + } + max--; + } + for (int i=0;i<15;i++) { + for (int j=0;j<15;j++) { + printf("%d\t",rows[i][j]); + } + printf("\n"); + } + + printf("\nYour maximum route is %d",rows[0][0]); + + return 0; +} \ No newline at end of file diff --git a/archives/18/src/utils.c b/archives/18/src/utils.c new file mode 100644 index 0000000..bd5f32c --- /dev/null +++ b/archives/18/src/utils.c @@ -0,0 +1,54 @@ +#include "utils.h" +#include +#include + +struct String add(struct String numb1, struct String numb2){ + byte carryover=0; + int digitCount=0; + char*str = malloc(0); + if (numb1.length>=numb2.length) { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb1.str[numb1.length-offset-1]; + } + } + } else { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb2.str[numb2.length-offset-1]; + } + } + } + if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m-V$eS}f>CF)kcDmRJv%4hQ zBoP_ZDTGyN9$A5#*%QK6+5?-7wA0hD9cPl+L0-$H-fgF2TDE>P-3 z)`8M&laq|lpFm#3(EC>q66i5j(z%Z zu(M@jF+E-36n4{TtW$-K%0%iGr)EpT%ZQD2)LoHh9HgcrWCI;5cM4nBud5SCJ3C@O zw`%ki7Tq-ft3z~=jQgzb(2KC1)K|6ZnT7Naf1!>_uj?1O^|)SUwawvio~^t2U+TKK z#C~7o>pCi~AA;J-K;43#Wpcm230+4WrCB0bI()veRGeBnd4)LrPNGMvJy!nwp}9Y)etbbaDqxI( z(^<5*#%|>;RPUynYAUURZp~xRO%K&nO8kGVL3*yHO5*=v4N=KoCGplAp&R{G#xp#q fpHe*?@GHU|IuL+or51DzJs+qNr&m+!hKK$KEdPcY diff --git a/src/main.c b/src/main.c index fe9522c..57370fc 100644 --- a/src/main.c +++ b/src/main.c @@ -1,168 +1,76 @@ #include #include "utils.h" +#define TARGET 2 + /* - If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. + By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. + +3 +7 4 +2 4 6 +8 5 9 3 - If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? +That is, 3 + 7 + 4 + 9 = 23. +Find the maximum total from top to bottom of the triangle below: - NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage. +75 +95 64 +17 47 82 +18 35 87 10 +20 04 82 47 65 +19 01 23 75 03 34 +88 02 77 73 07 63 67 +99 65 04 28 06 16 70 92 +41 41 26 56 83 40 80 70 33 +41 48 72 33 47 32 37 16 94 29 +53 71 44 65 25 43 91 52 97 51 14 +70 11 33 28 77 73 17 78 39 68 17 57 +91 71 52 38 17 14 91 43 58 50 27 29 48 +63 66 04 68 89 53 67 30 73 16 69 87 40 31 +04 62 98 27 23 09 70 98 73 93 38 53 60 04 23 - https://projecteuler.net/problem=17 +NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o) + https://projecteuler.net/problem=18 */ int main(int argc,char**argv) { - int totalCount=0; - int counter=1; - int i=1; - int hundredsDigit=-1; - int tensDigit=-1; - while (i<=1000) { - hundredsDigit=-1; - tensDigit=-1; - counter=i; - int currentCount=totalCount; - if (counter==1000) { - //onethousand (11) - totalCount+=11; - counter-=1000; - printf("onethousand"); - } - if (counter>=100) { - hundredsDigit=counter/100; - switch (hundredsDigit) { - case 1: - case 2: - case 6:{ - //onehundred (10) - totalCount+=10; - printf("%s",hundredsDigit==1?"one":hundredsDigit==2?"two":"six"); - }break; - case 3: - case 7: - case 8:{ - //threehundred (12) - totalCount+=12; - printf("%s",hundredsDigit==3?"three":hundredsDigit==7?"seven":"eight"); - }break; - case 4: - case 5: - case 9:{ - //fourhundred (11) - totalCount+=11; - printf("%s",hundredsDigit==4?"four":hundredsDigit==5?"five":"nine"); - }break; - } - printf("hundred"); - counter-=hundredsDigit*100; - } - if (counter>=10) { - tensDigit=counter/10; - if (tensDigit!=0) { - if (hundredsDigit!=-1) { - //and (3) - totalCount+=3; - printf("and"); - } - if (counter<20) { - switch (counter) { - case 10:{ - //ten (3) - totalCount+=3; - printf("ten"); - }break; - case 11:{ - //eleven (6) - totalCount+=6; - printf("eleven"); - }break; - case 12:{ - //twelve (5) - totalCount+=5; - printf("twelve"); - }break; - case 13: - case 14: - case 19:{ - //thirteen (8) - totalCount+=8; - printf("%s",counter==13?"thirteen":counter==14?"fourteen":"nineteen"); - }break; - case 15: - case 16:{ - //fifteen (7) - totalCount+=7; - printf("%s",counter==15?"fifteen":"sixteen"); - }break; - case 17: - case 18:{ - //seventeen (9) - totalCount+=9; - printf("%s",counter==17?"seventeen":"eighteen"); - }break; - } - counter=0; - } else { - switch (tensDigit) { - case 2: - case 3: - case 8: - case 9:{ - //twenty (6) - totalCount+=6; - printf("%s",tensDigit==2?"twenty":tensDigit==3?"thirty":tensDigit==8?"eighty":"ninety"); - }break; - case 4: - case 5: - case 6:{ - //forty (5) - totalCount+=5; - printf("%s",tensDigit==4?"forty":tensDigit==5?"fifty":"sixty"); - }break; - case 7:{ - //seventy (7) - totalCount+=7; - printf("seventy"); - }break; - } - counter-=tensDigit*10; - } - } + int rows[][15] = { + {75} + ,{95,64} + ,{17,47,82} + ,{18,35,87,10} + ,{20,4,82,47,65} + ,{19,1,23,75,3,34} + ,{88,2,77,73,7,63,67} + ,{99,65,4,28,6,16,70,92} + ,{41,41,26,56,83,40,80,70,33} + ,{41,48,72,33,47,32,37,16,94,29} + ,{53,71,44,65,25,43,91,52,97,51,14} + ,{70,11,33,28,77,73,17,78,39,68,17,57} + ,{91,71,52,38,17,14,91,43,58,50,27,29,48} + ,{63,66,4,68,89,53,67,30,73,16,69,87,40,31} + ,{4,62,98,27,23,9,70,98,73,93,38,53,60,4,23}}; + + int max=14; + for (int row=14;row>0;row--) { + for (int col=0;colnumb2)?numb1:numb2; } - if (counter>0) { - if (tensDigit==-1&&hundredsDigit!=-1) { - //and (3) - totalCount+=3; - printf("and"); - } - switch (counter) { - case 1: - case 2: - case 6:{ - //one (3) - totalCount+=3; - printf("%s",counter==1?"one":counter==2?"two":"six"); - }break; - case 3: - case 7: - case 8:{ - //three (5) - totalCount+=5; - printf("%s",counter==3?"three":counter==7?"seven":"eight"); - }break; - case 4: - case 5: - case 9:{ - //four (4) - totalCount+=4; - printf("%s",counter==4?"four":counter==5?"five":"nine"); - }break; - } + max--; + } + for (int i=0;i<15;i++) { + for (int j=0;j<15;j++) { + printf("%d\t",rows[i][j]); } - printf(" %d:%d\n",i,totalCount-currentCount); - i++; + printf("\n"); } - printf("%d",totalCount); + + printf("\nYour maximum route is %d",rows[0][0]); + return 0; } \ No newline at end of file