From 4449e40b69abde8760d9eed741ceec9a70007aea Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 17 Jul 2022 21:03:26 -0500 Subject: [PATCH] #15 done! Co-authored-by: sigonasr2 --- archives/15/current | Bin 0 -> 16040 bytes archives/15/src/executeall.sh | 20 +++++++++++++ archives/15/src/main.c.disabled | 35 ++++++++++++++++++++++ archives/15/src/output | 20 +++++++++++++ archives/15/src/threadedmain.c | 40 +++++++++++++++++++++++++ archives/15/src/utils.h | 7 +++++ current | Bin 15952 -> 16040 bytes src/executeall.sh | 20 +++++++++++++ src/main.c | 50 -------------------------------- src/main.c.disabled | 35 ++++++++++++++++++++++ src/output | 20 +++++++++++++ src/threadedmain.c | 40 +++++++++++++++++++++++++ 12 files changed, 237 insertions(+), 50 deletions(-) create mode 100755 archives/15/current create mode 100755 archives/15/src/executeall.sh create mode 100644 archives/15/src/main.c.disabled create mode 100644 archives/15/src/output create mode 100644 archives/15/src/threadedmain.c create mode 100644 archives/15/src/utils.h create mode 100755 src/executeall.sh delete mode 100644 src/main.c create mode 100644 src/main.c.disabled create mode 100644 src/output create mode 100644 src/threadedmain.c diff --git a/archives/15/current b/archives/15/current new file mode 100755 index 0000000000000000000000000000000000000000..64a880868d50db1e776e3cdb5e1f121864e0d2a6 GIT binary patch literal 16040 zcmeHOZEO_B8J;@~7y|eJL(E6vnuZ7(`LMxQgyM48URYOrxL_+#HC@iWweOnyaPRhl z9hJtFlPISPDQ%<%sjb@P4^o>SmKsI$N86)NKBSbIe^iaowZhV&($>&6a$3UneP`bH zSZ~fmYOD6oj{k#D98-G_ z^a`k^h#ZAc_(zq^^b5h`pP>3j2y1+Ts2Yuq$`1bwjIs6ii0SRW4& zv@t&)4)js+_&Veihj`7rnnau}Vg1Xh6q>*VtMHEjSIvLxEIjrm2!}hJ0wU-p!S=y{ zZG0pdM*ncc7>K7LiTLxTFbudL{YKV`WGo{YiKl=8qyJf>KlZFK5Q!(mP$r(T1_b)y zb!ruR_jR>*7+XS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/src/executeall.sh new file mode 100755 index 0000000..1f547c1 --- /dev/null +++ b/archives/15/src/executeall.sh @@ -0,0 +1,20 @@ +./sig build 1 & +./sig build 2 & +./sig build 3 & +./sig build 4 & +./sig build 5 & +./sig build 6 & +./sig build 7 & +./sig build 8 & +./sig build 9 & +./sig build 10 & +./sig build 11 & +./sig build 12 & +./sig build 13 & +./sig build 14 & +./sig build 15 & +./sig build 16 & +./sig build 17 & +./sig build 18 & +./sig build 19 & +./sig build 20 & \ No newline at end of file diff --git a/archives/15/src/main.c.disabled b/archives/15/src/main.c.disabled new file mode 100644 index 0000000..eece796 --- /dev/null +++ b/archives/15/src/main.c.disabled @@ -0,0 +1,35 @@ +#include +#include "utils.h" + +/* + Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. + + How many such routes are there through a 20×20 grid? + + + https://projecteuler.net/problem=14 +*/ + +void move(int x,int y,long*pathCount) { + if (x<21) { + move(x+1,y,pathCount); + } + if (y<21) { + move(x,y+1,pathCount); + } + if (x==20&&y==20) { + (*pathCount)++; + if (*pathCount%1000000==0) { + printf("%ld...",*pathCount); + } + } +} + +int main(int argc,char**argv) { + int x=0; + int y=0; + long pathCount=0; + move(x,y,&pathCount); + printf("\n\n%ld",pathCount); + return 0; +} \ No newline at end of file diff --git a/archives/15/src/output b/archives/15/src/output new file mode 100644 index 0000000..20a53d8 --- /dev/null +++ b/archives/15/src/output @@ -0,0 +1,20 @@ +1: 35345263800 +2: 17672631900 +3: 8597496600 +4: 4059928950 +5: 1855967520 +6: 818809200 +7: 347373600 +8: 141120525 +9: 54627300 +10: 20030010 +11: 6906900 +12: 2220075 +13: 657800 +14: 177100 +15: 42504 +16: 8855 +17: 1540 +18: 210 +19: 20 +20: 1 \ No newline at end of file diff --git a/archives/15/src/threadedmain.c b/archives/15/src/threadedmain.c new file mode 100644 index 0000000..c2e931b --- /dev/null +++ b/archives/15/src/threadedmain.c @@ -0,0 +1,40 @@ +#include +#include "utils.h" + +/* + Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. + + How many such routes are there through a 20×20 grid? + + + https://projecteuler.net/problem=14 +*/ + +void move(int x,int y,long*pathCount) { + if (x<21) { + move(x+1,y,pathCount); + } + if (x!=0&&y<21) { + move(x,y+1,pathCount); + } + if (x==20&&y==20) { + (*pathCount)++; + } +} + +int main(int argc,char**argv) { + int x=0; + int y=0; + int i=0; + int id=0; + while (argv[1][i]!='\0') { + y*=10; + y+=argv[1][i]-'0'; + i++; + } + id=y; + long pathCount=0; + move(x,y,&pathCount); + printf("\n\n%d:%ld",id,pathCount); + return 0; +} \ No newline at end of file diff --git a/archives/15/src/utils.h b/archives/15/src/utils.h new file mode 100644 index 0000000..d785fa2 --- /dev/null +++ b/archives/15/src/utils.h @@ -0,0 +1,7 @@ +#define true 1 +#define false 0 +#define boolean char +struct String{ + int length; + char*str; +}; \ No newline at end of file diff --git a/current b/current index ed41d39e4320d10ad01a6e8bbe0e3226c1855466..64a880868d50db1e776e3cdb5e1f121864e0d2a6 100755 GIT binary patch delta 2240 zcmZ`)eM}Tb6rWk{fHhEd`S5^Z@6@7FTJR&)nn56`k%yuW|l4(qz*A|vf?Hy4p-=d^@7V7vl{CSH>rnDxqa*ZZ-#(5Ljd@UqlNya z&*wgNhqs(~^U^2$N2lnvifAjG&Dc_ug~_bN5;CZ#&VoA`4YU)QZ4PkRifI)rWjN>{ zv*`%-%|ct-@nHL*BW;Jej2uB#cK0-en!)@k>B#3 z`wIhKU_8%>OE>KUtLzqN6*dMMaG+LHg|XicyYrkU^@){X|98IjBUQ6aV2N?0TiO8?e`P(>Qx$bCn4^UKlW3%P zTxzNVyGi>Eki_zSLG4>sLuo~ASsdzHF6>_$mY0VWs)Sn>!*W`kR3D`7BOPNTST@v` z)*0y)#sFNu6IlojGCJMThnw68R-sXYoWe@pgr{^2JYM*tI7B0o^#pcHEYT{eC0hIY!H1m zqmErncHD$TO*@9zh!{Z(AVv|7A+{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F9j2^5RQFs3DVXaD~{*@nBo{)3W*yR}d!= z$%C!J;GC*x5!7u05vcZ~DRXaRz(00(;GHDWK!Jv|d@wn1w_+hK-U6%&oq@T|8@RbHbvY)v7~ zR}EELzOnmt#QCmqGr58TN-Bx7AIJU&+;S=O5ujTYZy1kAC3qqojyI26pdP&%ddmcv zI49?D8sXqph398!&x}oI03$G)91h6HY3n!NHpv6 zIA7nv6Y!dQ9b9X!k|kEPC=RX#u|=0vZgnsK;TBztaBBo&Elu~!z$u4Hm~R<_Oi+cs zpd@zit#v>w*aRcN0Azy_q=J(0BZcCSCORkC3_C-6Xcr`!d@vo7AQzHoBg}_%`Iu^F zMjZSE#8w?fS_9D6ilML_YYm7_4P;=pwdsDvrr4Je1^-cP7VQRcM^o`BR(2@YDD2&_ Loeo26$CiHqISsHA diff --git a/src/executeall.sh b/src/executeall.sh new file mode 100755 index 0000000..1f547c1 --- /dev/null +++ b/src/executeall.sh @@ -0,0 +1,20 @@ +./sig build 1 & +./sig build 2 & +./sig build 3 & +./sig build 4 & +./sig build 5 & +./sig build 6 & +./sig build 7 & +./sig build 8 & +./sig build 9 & +./sig build 10 & +./sig build 11 & +./sig build 12 & +./sig build 13 & +./sig build 14 & +./sig build 15 & +./sig build 16 & +./sig build 17 & +./sig build 18 & +./sig build 19 & +./sig build 20 & \ No newline at end of file diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 58767cf..0000000 --- a/src/main.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include "utils.h" - -/* - The following iterative sequence is defined for the set of positive integers: - - n → n/2 (n is even) - n → 3n + 1 (n is odd) - - Using the rule above and starting with 13, we generate the following sequence: - 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 - - It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. - - Which starting number, under one million, produces the longest chain? - - NOTE: Once the chain starts the terms are allowed to go above one million. - - - https://projecteuler.net/problem=14 -*/ - -int main(int argc,char**argv) { - int maxChain=0; - long maxNumb=0; - int counter=1; - while (counter<1000000) { - //printf("Calculating %d...\n",counter); - long numb=counter; - int chainCount=0; - while (numb!=1) { - if (numb%2==0) { - numb/=2; - } else { - numb=3*numb+1; - } - chainCount++; - //printf("%d>",numb); - } - if (chainCount>maxChain) { - maxChain=chainCount; - maxNumb=counter; - printf("Max chain is now %d (%d)...\n",maxChain,maxNumb); - } - counter++; - } - printf("\n\nMax chain count is %d for number %d\n",maxChain,maxNumb); - - return 0; -} \ No newline at end of file diff --git a/src/main.c.disabled b/src/main.c.disabled new file mode 100644 index 0000000..eece796 --- /dev/null +++ b/src/main.c.disabled @@ -0,0 +1,35 @@ +#include +#include "utils.h" + +/* + Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. + + How many such routes are there through a 20×20 grid? + + + https://projecteuler.net/problem=14 +*/ + +void move(int x,int y,long*pathCount) { + if (x<21) { + move(x+1,y,pathCount); + } + if (y<21) { + move(x,y+1,pathCount); + } + if (x==20&&y==20) { + (*pathCount)++; + if (*pathCount%1000000==0) { + printf("%ld...",*pathCount); + } + } +} + +int main(int argc,char**argv) { + int x=0; + int y=0; + long pathCount=0; + move(x,y,&pathCount); + printf("\n\n%ld",pathCount); + return 0; +} \ No newline at end of file diff --git a/src/output b/src/output new file mode 100644 index 0000000..20a53d8 --- /dev/null +++ b/src/output @@ -0,0 +1,20 @@ +1: 35345263800 +2: 17672631900 +3: 8597496600 +4: 4059928950 +5: 1855967520 +6: 818809200 +7: 347373600 +8: 141120525 +9: 54627300 +10: 20030010 +11: 6906900 +12: 2220075 +13: 657800 +14: 177100 +15: 42504 +16: 8855 +17: 1540 +18: 210 +19: 20 +20: 1 \ No newline at end of file diff --git a/src/threadedmain.c b/src/threadedmain.c new file mode 100644 index 0000000..c2e931b --- /dev/null +++ b/src/threadedmain.c @@ -0,0 +1,40 @@ +#include +#include "utils.h" + +/* + Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. + + How many such routes are there through a 20×20 grid? + + + https://projecteuler.net/problem=14 +*/ + +void move(int x,int y,long*pathCount) { + if (x<21) { + move(x+1,y,pathCount); + } + if (x!=0&&y<21) { + move(x,y+1,pathCount); + } + if (x==20&&y==20) { + (*pathCount)++; + } +} + +int main(int argc,char**argv) { + int x=0; + int y=0; + int i=0; + int id=0; + while (argv[1][i]!='\0') { + y*=10; + y+=argv[1][i]-'0'; + i++; + } + id=y; + long pathCount=0; + move(x,y,&pathCount); + printf("\n\n%d:%ld",id,pathCount); + return 0; +} \ No newline at end of file