exercism/c/collatz-conjecture/collatz_conjecture.c

24 lines
276 B
C
Raw Permalink Normal View History

2024-06-09 22:28:04 -04:00
#include "collatz_conjecture.h"
int steps(int start) {
if (start < 1) {
return ERROR_VALUE;
}
int count = 0;
while (start != 1) {
if (start % 2 == 0) {
start /= 2;
} else {
start = start * 3 + 1;
}
count++;
}
return count;
}