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