My omnium-gatherom of scripts and source code.
at main 70 lines 1.4 kB view raw
1/* 2 * ===================================================================================== 3 * 4 * Filename: functions.c 5 * 6 * Description: code golf solutions 7 * 8 * Version: 1.0 9 * Created: 04/19/2023 09:42:21 PM 10 * Revision: none 11 * Compiler: clang 12 * 13 * Author: Sunglow 14 * 15 * ===================================================================================== 16 */ 17#include <stdlib.h> 18#include <stdio.h> 19 20void abundant(void) { 21 for (int i = 0; i <= 200; ++i) { 22 int accumulator = 0; 23 24 for (int j = 1; j < i; ++j) { 25 if (i % j == 0) 26 accumulator += j; 27 } 28 if (accumulator > i) 29 printf("%d\n", i); 30 } 31} 32 33void abundant_long(void) { 34 for (int i = 0; i <= 1000; ++i) { 35 int accumulator = 0; 36 37 for (int j = 1; j < i; ++j) { 38 if (i % j == 0) 39 accumulator += j; 40 } 41 if (accumulator > i) 42 printf("%d\n", i); 43 } 44} 45 46int collatz_calculator(const int n, int iteration) { 47 ++iteration; 48 if (n == 1) { 49 return iteration; 50 } else if (n % 2 == 0) { 51 iteration = collatz_calculator(n / 2, iteration); 52 } else { 53 iteration = collatz_calculator(n*3 + 1, iteration); 54 } 55 return iteration; 56} 57void collatz(void) { 58 for (int i = 1; i <= 1000; ++i) 59 printf("%d\n", collatz_calculator(i,0)-1); 60} 61 62/* 63void divisors(void) { 64 for (int i = 0; i <= 100; ++i) { 65 int arr[i/2]; 66 for (int j = 1; j < i/2; ++j) { 67 } 68 } 69} 70*/