#Collatz Conjecture [Zig]

6 messages · Page 1 of 1 (latest)

minor folio
#

I suspect there is a bug in the tests of this exercise, but I would like to make sure before I submit a report.

When trying to run the tests, I get the following error:
test_collatz_conjecture.zig:5:44: error: root struct of file 'collatz_conjecture' has no member named 'ComputationError'

I'm not sure if it might be an error in my code, I've never touched Zig before today. Thank you.

pub fn steps(number: usize) anyerror!usize 
{
    var count: usize = 0;
    var value: usize = number;

    while (value != 1)
    {
        count += 1;

        if (value % 2 == 0)
        {
            value /= 2;
            continue;
        }
        value = (value * 3) + 1;
    }
    return count;
}

maiden dagger
#

Are you supposed to define that error then throw it on invalid inputs?

minor folio
#

Yep, that was it. My apologies, I didn't see anything about that in the instructions. Thanks very much for your help.

maiden dagger
#

Sometimes you need to read the tests, too

minor folio
#

Gotcha, I'll keep that in mind moving forward. Just discovered Exercism this week. Is there anything I should do to mark this help issue as resolved?

maiden dagger
#

✅ on the top post