Skip to content

Instantly share code, notes, and snippets.

@stevedev
Created January 21, 2013 05:50
Show Gist options
  • Save stevedev/4583887 to your computer and use it in GitHub Desktop.
Save stevedev/4583887 to your computer and use it in GitHub Desktop.

Ruby:

def factorial(n)
  return 1 if n.zero?
  1.upto(n).inject(:*)
end

PHP:

<?php
function factorial($number) { 
    if ($number < 2) { 
        return 1; 
    } else { 
        return ($number * factorial($number-1)); 
    } 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment