mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 06:43:09 -05:00
19 lines
461 B
Zig
19 lines
461 B
Zig
// Please implement the `ComputationError.IllegalArgument` error.
|
|
|
|
pub const ComputationError = error{IllegalArgument};
|
|
|
|
pub fn steps(number: usize) anyerror!usize {
|
|
if (number < 1) return ComputationError.IllegalArgument;
|
|
|
|
var count: usize = 0;
|
|
var temp: usize = number;
|
|
while (temp > 1) : (count += 1) {
|
|
if (temp % 2 == 0) {
|
|
temp /= 2;
|
|
} else {
|
|
temp = temp * 3 + 1;
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|