Skip to content

Instantly share code, notes, and snippets.

@jougene
Last active June 10, 2016 12:23
Show Gist options
  • Save jougene/e1359ae72a21f721374945ac7c091eec to your computer and use it in GitHub Desktop.
Save jougene/e1359ae72a21f721374945ac7c091eec to your computer and use it in GitHub Desktop.
function divide($a, $b)
{
    $divisor = $b;
    if ($b > $a) {
        return 0;
    }

    $res = 1;
    while (($b + $b) <= $a) {
        $b += $b;
        $res += $res;
    }

    return $res + divide($a - $b, $divisor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment