mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-09 13:20:48 -05:00
24 lines
276 B
C
24 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;
|
||
|
}
|