diff --git a/archives/15/current b/archives/15/current new file mode 100755 index 0000000..64a8808 Binary files /dev/null and b/archives/15/current differ diff --git a/archives/15/src/executeall.sh b/archives/15/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 ed41d39..64a8808 100755 Binary files a/current and b/current differ 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