• Post Reply Bookmark Topic Watch Topic
  • New Topic
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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Can you explain this to me please?

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello good afternoon.  I dont understand this sentence
""  return <-(b*Power(b,x-1))  """
In the video it says that the base is multiplied by the base..., and the x I guess would be the number of times the base is multiplied by itself, right? Let's suppose that the base is 2, and the exponent is 3. 2 * 2=4.. where does that four stay until it is multiplied by 2 again?
Or the x that function fulfills? Thank you.
RECURSIVIDADINGLES.png
[Thumbnail for RECURSIVIDADINGLES.png]
 
Marshal
Posts: 79961
396
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know at present. There are all sorts of ways to calculate powers, some recursive. Please copy the code into text because the screenshot isn't easy to read. Also what language is it?
 
Rancher
Posts: 326
14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First: Please post code and/or error messages as text instead of pictures. This makes it easier to analyze and read (especially on mobile devices). Please use code-tags when posting code.

Second: This is a recursive function. Each iteration is pushed onto the stack and held there until the next level down returns. This keeps recursing until the final exit condition is met (usual a counter hit 0). In simple maths raising a base to an exponential power is just one step more as multiplying: Multiplication is adding a number N byitself X times. Exponentiation is the same but the base operation is multiply instead of add - which in term gets broken down into consecutive additions. Or in other terms: Exponentiation is adding a number N X times to itself - repating that E times.

So when raising 3 to the power of 3 that is 3x3x3 = (3+3+3)+(3+3+3)+(3+3+3) = 27.

Doing it recursive is by using the exponent E as counter and call the recursive function by subtracting 1 each time.
As by definition raising N to the power of 0 results in 1. Raising N to the power of 1 results in N itself.
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Don't know at present. There are all sorts of ways to calculate powers, some recursive. Please copy the code into text because the screenshot isn't easy to read. Also what language is it?


It is a program that uses pseudocode. It's called PSEINT. OK thanks I get on mind
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Valdeolmillos wrote:

Campbell Ritchie wrote:Don't know at present. There are all sorts of ways to calculate powers, some recursive. Please copy the code into text because the screenshot isn't easy to read. Also what language is it?


It is a program that uses pseudocode. It's called PSEINT. OK thanks I get on mind


I understood that counters are written like this:
accumulator ← accumulator + X .
In this example, I thought it was building up on the word power:
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic