Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queues - Cara Comfort - recursion-tracing #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cecomfort
Copy link

Recursion Tracing

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
Did you define all the recursion terms? yes
How do you feel about tracing recursive problems? (good, bad, ugly, neutral) good
Would you like help/follow up about recursion? Provided solutions to the added fun would be very helpful! I attempted the added fun for mystery2, but -123/10 and -123%10 did not give the -12 and -3 like anticipated.

@sudocrystal
Copy link

re: answers to the added fun

Here ya go:

def mystery2(n)
  if n < 0
    return -1 * mystery2(-n)
  elsif n < 10
    return n
  else
    return (n%10) + mystery2(n/10)
  end
end

def mystery5(s)
  if s.length == 0
    return ""
  elsif s[0].match(/[a-zA-Z]/)
    return "*" + mystery5(s[1..-1])
  else
    return s[0] + mystery5(s[1..-1])
  end
end

def mystery6(s)
  if s.length < 2
    return s
  else
    return mystery6(s[1..-1]) + s[0]
  end
end

@sudocrystal
Copy link

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants