summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-07 00:29:25 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-07 00:29:25 +0100
commit0ac9224655469a99a367869e9a36c39a44c72cb6 (patch)
tree6fcc700ebfe9563690aff264dcd838f7352f06d8
parentpreverjanje znanja matematike - popravljena ura generiranja (diff)
downloadsola-gimb-2-0ac9224655469a99a367869e9a36c39a44c72cb6.tar
sola-gimb-2-0ac9224655469a99a367869e9a36c39a44c72cb6.tar.gz
sola-gimb-2-0ac9224655469a99a367869e9a36c39a44c72cb6.tar.bz2
sola-gimb-2-0ac9224655469a99a367869e9a36c39a44c72cb6.tar.lz
sola-gimb-2-0ac9224655469a99a367869e9a36c39a44c72cb6.tar.xz
sola-gimb-2-0ac9224655469a99a367869e9a36c39a44c72cb6.tar.zst
sola-gimb-2-0ac9224655469a99a367869e9a36c39a44c72cb6.zip
-rw-r--r--mat/euler/14/Makefile2
-rwxr-xr-xmat/euler/14/a.outbin0 -> 8432 bytes
-rw-r--r--mat/euler/14/prog.c29
-rw-r--r--mat/euler/15/Makefile2
-rwxr-xr-xmat/euler/15/a.outbin0 -> 8432 bytes
-rw-r--r--mat/euler/15/prog.c24
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
new file mode 100755
index 0000000..8a10ce9
--- /dev/null
+++ b/mat/euler/14/a.out
Binary files differ
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
new file mode 100755
index 0000000..cd711e5
--- /dev/null
+++ b/mat/euler/15/a.out
Binary files differ
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;
+}