summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMr. Sam <samuel@yakubos.org>2026-07-19 23:40:53 +0100
committerMr. Sam <samuel@yakubos.org>2026-07-19 23:40:53 +0100
commit536f57988cde7fb22e52b3c75b3986cd0a457e00 (patch)
treeca7b6b44dfba2df0655848a471a24bd714540b2d
Remade because I kinda deleted the old, perfect version
-rwxr-xr-xMakefile24
-rw-r--r--main.c29
2 files changed, 53 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100755
index 0000000..9f1cea8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,24 @@
+#clear ; vim main.c ; gcc main.c -Wall -Wextra -Wpedantic -std=c99 -o collatz
+
+PREFIX = /usr/local
+
+CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os
+
+CC = gcc
+
+SRC = main.c
+
+all:
+ ${CC} ${CFLAGS} ${SRC} -o collatz
+
+.PHONY: all clean dist install uninstall
+
+install: all
+ ${CC} ${CFLAGS} ${SRC} -o stats
+ cp -f stats ${PREFIX}/bin
+ chmod 755 ${DESTDIR}${PREFIX}/bin/stats
+
+uninstall:
+ rm -f ${PREFIX}/bin/stats
+
+
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..7e289a3
--- /dev/null
+++ b/main.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+void PrintHelp(void) {
+ printf("Usage: collatz <number>"
+ "\nMade by samuel@yakubos.org\n\n");
+}
+
+int main(int argc, char *argv[]) {
+ if ( argc < 2 || argc > 2) {
+ PrintHelp();
+ return 1;
+ }
+ char *endptr;
+ long int num;
+ int steps = 0;
+ num = strtol(argv[1], &endptr, 10);
+
+ printf("%li\n", num);
+ while ( num > 1 ) {
+ num = ( num & 1 ) ? num * 3 + 1 : num / 2;
+ printf("%li\n", num);
+ steps++;
+ }
+
+ printf("%s took %d steps\n", argv[1], steps);
+
+}
+