diff options
-rw-r--r-- | mat/euler/14/Makefile | 2 | ||||
-rwxr-xr-x | mat/euler/14/a.out | bin | 0 -> 8432 bytes | |||
-rw-r--r-- | mat/euler/14/prog.c | 29 | ||||
-rw-r--r-- | mat/euler/15/Makefile | 2 | ||||
-rwxr-xr-x | mat/euler/15/a.out | bin | 0 -> 8432 bytes | |||
-rw-r--r-- | mat/euler/15/prog.c | 24 |
6 files changed, 57 insertions, 0 deletions
diff --git a/mat/euler/14/Makefile b/mat/euler/14/Makefile new file mode 100644 index 0000000..2def8af --- /dev/null +++ b/mat/euler/14/Makefile @@ -0,0 +1,2 @@ +default: + gcc prog.c diff --git a/mat/euler/14/a.out b/mat/euler/14/a.out Binary files differnew file mode 100755 index 0000000..8a10ce9 --- /dev/null +++ b/mat/euler/14/a.out diff --git a/mat/euler/14/prog.c b/mat/euler/14/prog.c new file mode 100644 index 0000000..bb0daf6 --- /dev/null +++ b/mat/euler/14/prog.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> +#define COLLATZ(n) n % 2 == 0 ? n / 2 : 3 * n + 1 +int main (int argc, char ** argv) { + if (argc != 1+1) { + fprintf(stderr, "uporaba: %s <stevilo>\nprimer-najd. collatzova veriga pod zač. 1M: %s 1000000\n", argv[0], argv[0]); + return 1; + } + unsigned long int n = strtol(argv[1], NULL, 10); + unsigned long int c = 0; // števeC + unsigned long int a = 0; // verigA + unsigned long int m = 0; // maksimalna dolžina verige + unsigned long int z = 0; // trenutna Zmagovalna številka z najdaljšo verigo + for (; n >= 1; n--) { + // fprintf(stderr, "\rračunam... potrebnih še %lu iteracij.", n); // botlnck + a = n; + c = 1; + while (a != 1) { + a = COLLATZ(a); + c++; + } + if (c > m) { + m = c; + z = n; + } + } + fprintf(stdout, "\rkonec. najdaljša veriga se začne z %lu in ima %lu elementov.\n", z, m); + return 0; +} diff --git a/mat/euler/15/Makefile b/mat/euler/15/Makefile new file mode 100644 index 0000000..2def8af --- /dev/null +++ b/mat/euler/15/Makefile @@ -0,0 +1,2 @@ +default: + gcc prog.c diff --git a/mat/euler/15/a.out b/mat/euler/15/a.out Binary files differnew file mode 100755 index 0000000..cd711e5 --- /dev/null +++ b/mat/euler/15/a.out diff --git a/mat/euler/15/prog.c b/mat/euler/15/prog.c new file mode 100644 index 0000000..4151bfb --- /dev/null +++ b/mat/euler/15/prog.c @@ -0,0 +1,24 @@ +#include <stdio.h> +#include <stdlib.h> +int main (int argc, char ** argv) { + if (argc != 1+1) { + fprintf(stderr, "uporaba: %s <stevilka>\nprimer za mrežo 20x20: %s 20\n", argv[0], argv[0]); + return 1; + } + unsigned long int n = strtol(argv[1], NULL, 10); + unsigned long int s = 0; // Seštevek + unsigned long int i = 0; // Index iteracije + unsigned long int x = 0; // X + for (i = 0; i <= n-1; i++) { + // najprej diagonale + fprintf(stderr, "%lu\n", i); + s = s + (n-(i))+(n-(i)); + } + for (i = 1; i <= n; i++) { + for (x = 0; x <= i-1; x++) { + s = s + 2*( (n-i)+(n-(x+1)) ); + } + } + fprintf(stdout, "rezultat je: %lu\n", s); + return 0; +} |