Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.


  • How to write a recursive method

  • Step one- write ‘if’ a. There must be two cases: a recursive case (where the method calls itself) b. and a base case (where the method does not)

  • Handle the simplest case(s). a. Simplest = no recursive call needed (no looping)
  • Write the recurisve call(s) a. On the next simplest input/state
  • Assume the recursive call works (maybe store the result in a variable) a. Ask yourself, what does it do? b. How does it help?

9! = 9*8*7*6.. 10! = 10*9! n! = n * (n - 1)! -> a recursive definition of factorial

“`ruby def factorial(n) if n == 0

return 1


result = factorial(n - 1) #computes n-1 factorial
result * n

end end