Sha256: 350f327c487daee5fe64dcb4de49288a30cb9a7cd4b607f8610ab3feb0ca14f9

Contents?: true

Size: 379 Bytes

Versions: 134

Compression:

Stored size: 379 Bytes

Contents

<?php

function steps($number)
{
    $stepCount = 0;
    if ($number < 1) {
        throw new InvalidArgumentException('Only positive numbers are allowed');
    }
    do {
        if ($number === 1) {
            break;
        }
        $stepCount++;
        $number = ( $number % 2 === 0 ? $number / 2 : 3 * $number + 1);
    } while ($number !== 0);

    return $stepCount;
}

Version data entries

134 entries across 134 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.77 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.76 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.75 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.74 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.73 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.72 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.71 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.70 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.69 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.68 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.67 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.66 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.65 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.64 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.63 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.62 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.61 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.60 tracks/php/exercises/collatz-conjecture/example.php
trackler-2.2.1.59 tracks/php/exercises/collatz-conjecture/example.php