On Fri, Jun 1, 2012 at 2:50 AM, Spencer Pottebaum <[email protected]> wrote:
> This is a homework question and I'm really confused by it:
>
> the method exp(x,y) is passed two integers and returns x^Y write a
> recursive version of exp(s,y) in Ruby.
>
> this is what I have:
>
> def exp(x,y)
>
>  if y = 1
>  return x
>
> return x * exp(x, y-1)
>
> is this correct?

No, you are missing an "end". ;-)

You could also include treatment for y == 0.  (Hint: a case block might help.)

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to