Sha256: 1e9a06ae6f3374236a3b46811a02fec37a8fbe50320c4660dafae08ff3636d01

Contents?: true

Size: 540 Bytes

Versions: 166

Compression:

Stored size: 540 Bytes

Contents

using System;

public static class CollatzConjecture
{
    public static int Steps(int number)
    {
        if(number <= 0)
        {
            throw new ArgumentException("Only positive numbers are allowed");
        }

        int stepCount = 0;

        while(number != 1)
        {
            if(number % 2 == 0)
            {
                number /= 2;
            }
            else
            {
                number = (number * 3) + 1;
            }

            stepCount++;
        }

        return stepCount;
    }
}

Version data entries

166 entries across 166 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.179 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.178 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.177 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.176 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.175 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.174 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.173 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.172 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.171 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.170 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.169 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.167 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.166 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.165 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.164 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.163 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.162 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.161 tracks/csharp/exercises/collatz-conjecture/Example.cs
trackler-2.2.1.160 tracks/csharp/exercises/collatz-conjecture/Example.cs