mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 06:43:09 -05:00
23 lines
276 B
C
23 lines
276 B
C
#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;
|
|
}
|