programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Liutauras Vilda
Sheriffs:
• Paul Clapham
• Jeanne Boyarsky
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Piet Souris
• Carey Brown
Bartenders:
• Jesse Duncan
• Frits Walraven
• Mikalai Zaikin

# Recursion Problem

Greenhorn
Posts: 1
• Number of slices to send:
Optional 'thank-you' note:
Does anybody know how I can solve this problem, at this point I am just looking for answers, I'm stressed and just want to complete this assignment, if you do know and can provide me with the proper code to solve it, I would greatly appreciate it, thank you.
Screenshot-16-05-2022-071003.jpg

Saloon Keeper
Posts: 7355
170
• Number of slices to send:
Optional 'thank-you' note:
Welcome to the Ranch.

No, we won't solve your problem for you, but we'll help you do it yourself. So: what do you have so far? If you haven't started, what ideas have you had?

Greenhorn
Posts: 29
1
• Number of slices to send:
Optional 'thank-you' note:
Is the problem just looking for integers or are you supposed to find a real number such that x^x = N?

Sorry the side of me that loves math came out there for a minute.

I would suggest looking here.   https://www.geeksforgeeks.org/recursive-functions/  it doesn't have the exact problem you have but it has a good discussion about recursive functions and an example in Java ( or several other languages ).

Marshal
Posts: 75866
361
• Number of slices to send:
Optional 'thank-you' note:
It is easy enough to write an int recursivePower() method such that recursivePower(3) returns 27. I am not sure whether that is what they wanted. I got an overflow error with recursivePower(10).

Saloon Keeper
Posts: 4993
186
• 1
• Number of slices to send:
Optional 'thank-you' note:
No, that is not what they want. They want a recursive solution for x^x = N. To be able to solve this for higher values of x, you might take the logs of both sides. How would you turn Newton-Raphson or a binary search into a recursive one?

Saloon Keeper
Posts: 9348
78
• Number of slices to send:
Optional 'thank-you' note:
How does "F(x+1)" apply to solving the problem with doubles?

Carey Brown
Saloon Keeper
Posts: 9348
78
• Number of slices to send:
Optional 'thank-you' note:
A non-recursive approach. If I knew how to use logs that would probably be more direct than this (?).

Saloon Keeper
Posts: 14010
315
• Number of slices to send:
Optional 'thank-you' note:
This is another example of a really stupid assignment to test people on recursion. Not only that, but it's poorly written as well.

Here's the only sensible way I can see the solution be implemented, following the assignment to the letter:

Piet Souris
Saloon Keeper
Posts: 4993
186
• Number of slices to send:
Optional 'thank-you' note:
Or this, a recursive binary search. Quite useless, as Stephan says, but fun to make.

 pie. tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton