parent
9f3ef6f8fa
commit
4449e40b69
BIN
archives/15/current
Executable file
BIN
archives/15/current
Executable file
Binary file not shown.
20
archives/15/src/executeall.sh
Executable file
20
archives/15/src/executeall.sh
Executable file
@ -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 &
|
35
archives/15/src/main.c.disabled
Normal file
35
archives/15/src/main.c.disabled
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#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;
|
||||||
|
}
|
20
archives/15/src/output
Normal file
20
archives/15/src/output
Normal file
@ -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
|
40
archives/15/src/threadedmain.c
Normal file
40
archives/15/src/threadedmain.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#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;
|
||||||
|
}
|
7
archives/15/src/utils.h
Normal file
7
archives/15/src/utils.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
#define boolean char
|
||||||
|
struct String{
|
||||||
|
int length;
|
||||||
|
char*str;
|
||||||
|
};
|
20
src/executeall.sh
Executable file
20
src/executeall.sh
Executable file
@ -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 &
|
50
src/main.c
50
src/main.c
@ -1,50 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#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;
|
|
||||||
}
|
|
35
src/main.c.disabled
Normal file
35
src/main.c.disabled
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#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;
|
||||||
|
}
|
20
src/output
Normal file
20
src/output
Normal file
@ -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
|
40
src/threadedmain.c
Normal file
40
src/threadedmain.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user