A Challenge!

Started by AngryPacman, January 15, 2012, 10:34:24 am

Previous topic - Next topic

AngryPacman

My brother and I stumbled across something interesting whilst playing around with wolfram between watching Digimon and gaining weight. For some reason we got onto square roots of 2 to power x. I noticed that when x is even, then result is always whole, and when x is odd, the result is always the same as x-1, multiplied by sqrt(2). I also noticed that the whole number in the result doubles with every even number x. To illustrate what I'm saying...
sqrt(2^0) = 1 -> As 2^0 = 1.
sqrt(2^1) = 1 * sqrt(2) -> Previous result multiplied by sqrt(2)
sqrt(2^2) = 2 -> Original result (1) doubled.
sqrt(2^3) = 2 * sqrt(2) -> Previous result multiplied by sqrt(2)
sqrt(2^4) = 4 -> Last whole number result (2) doubled.
sqrt(2^5) = 4 * sqrt(2) -> Previous result multiplied by sqrt(2)
sqrt(2^6) = 8 -> Last whole number result (4) doubled.
sqrt(2^7) = 8 * sqrt(2) -> Previous result multiplied by sqrt(2)
And so on in that fashion. I'm not surprised by this, but I found it intriguing, and I'm almost certainly not the first one to find it (but I've never seen it before). My brother, however, was really fascinated and challenged me to write a little formula to calculate the result of sqrt(2^n). I've decided to take him up on that and try and write it in Ruby.
The first thing I realized I had to do was determine if n was even or odd. Easy stuff there (i = n % 2), no problem. The easy part is the even formula. That's still pretty easy (x = Math.sqrt(2 ** n)).
The part that stumped me a bit was the odd formula, but I figured out eventually, whilst typing this topic, so it's actually kinda pointless because I was going to ask for help but now I don't need it.  :facepalm: I ended up going with x = Math.sqrt(2 ** (n - 1)) * Math.sqrt(2), but any improvements would be accepted before I rub my brother's face in this relatively simple fomula.
Here's the method:
def whocares(n)
  i = n % 2
  if i == 0
    x = Math.sqrt(2 ** n)
  elsif i == 1
    x = Math.sqrt(2 ** (n - 1))
    x = x.to_s + (" root 2") # Or x *= Math.sqrt(2)
  end
  return x
end

Does anyone know anything about this formula? Is it famous and I'm just stupid? Are there any improvements that could be done?

Anyway, thanks for being a sound board without even knowing it. I just happened to solve this pretty simple problem too soon.  :facepalm: I'mma post this anyway.
G_G's a silly boy.

winkio

This is not famous, this is simple, I think you are just fooling yourself.

sqrt(2^n) is the same as (root 2)^n.  So of course increasing n is the same as multiplying by root 2.  And of course even exponents will cause the powers of two to occur.

Blizzard

January 15, 2012, 01:57:19 pm #2 Last Edit: January 15, 2012, 02:10:05 pm by Blizzard
Crap, winkio beat me to it.

Same works for every x in sqrt(xn). It doesn't only equal sqrt(x)n, it also equals xn/2, hence:

sqrt(8) = sqrt(23) = sqrt(2)3 = 23/2 = 2 * 21/2 = 2 * sqrt(2)

That shows that this works:

sqrt(8) = sqrt(4 * 2) = sqrt(4) * sqrt(2) = 2 * sqrt(2)

EDIT: Also, you're not stupid for figuring this out on your own. It would rather say you are the opposite. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

AngryPacman

Yeah, I didn't think it was all that difficult or special, and the pattern became clear really quickly. I'd just never seen it before, never heard any special correlation between roots of powers of x. But because I love mathematical beauty, I just had to figure it out for myself. Thanks for telling me that Blizz.

Also winkio was totally right XD
G_G's a silly boy.