mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 14:43:10 -05:00
20 lines
461 B
Zig
20 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;
|
||
|
}
|