summaryrefslogtreecommitdiffstats
path: root/mat/euler/14
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 /mat/euler/14
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
Diffstat (limited to 'mat/euler/14')
-rw-r--r--mat/euler/14/Makefile2
-rwxr-xr-xmat/euler/14/a.outbin0 -> 8432 bytes
-rw-r--r--mat/euler/14/prog.c29
3 files changed, 31 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;
+}