Test: add case for odd starting value in Collatz sequence

Overview
Adds a missing test case for handling odd-number Collatz inputs.

Motivation
Odd starts (like 25) help surface an easy mistake: using / produces floats, which breaks the integer sequence.
Using // keeps the logic consistent.
This test highlights the issue, and I suggest recommending // in the implementation

Changes
Added test_odd_number_start to verify steps(25)

One of the existing tests is 12. Doesn’t that capture the same condition already? 12 → 6 → 3 → odd

1 Like

Yeah, you are right but I am still curious why using / instead of // gives the same result. I ran the tests agin and they work fine in both cases: / and //. Should not / give a float value?

What language? Does it matter if it’s a float or int? Why? Where? You’re returning the step count, not the value.

Python

I don’t know any python. But I think the OP’s reasoning is like so, if I divide 3 / 2 in a language where / returns a float, the result would be 1.5 and checks would fail.

I think this is not a concern here because only even numbers are divided (by 2) and so the result would be an “exact” float like 3.0 or 4.0, which can be compared with 1 (assuming it is implicitly converted to 1.0, or that the float is implicitly converted to an int).

This is an exercise for the OP to think through their solution and identity the issue, or lack thereof :wink: I’m fairly familiar with this exercise and various solutions in Python.

1 Like

Oh, sorry. I thought that there was a problem in communication. My bad :sweat_smile:

1 Like

ok i get it now, odd numbers are never divided by 2 so there is never a fraction part. Thanks for clearing this

If you do use / in Python, you’d still get a float even if the float is a whole number. The same question applies, though.