lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 27 Sep 2015 09:35 PM |
| find the square root of a number without using math.sqrt or decimal exponents (e.g. x^.5) |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 09:43 PM |
function squirt(x) local try = 0 repeat try = try+1e-010 until (try^2)-.0001<=x<=(try^2)+.0001 or x/2<=try return x/2<=try and "No Root Found" or try end
Perhaps? |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 09:43 PM |
lol you silly's square root is essentially the something to the power of a half!!
function sqart(num) return num^(1/2) end
print(sqart(22))
morashsPeasant is worshipping Dermon |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 09:44 PM |
something to the power of a half**
morashsPeasant is eating |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 09:44 PM |
| He said no decimal exponents.. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 09:45 PM |
lol i cri evertim
morashsPeasant is Dermon |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 09:47 PM |
Ok, I still win
function sqart(num) return math.log(num)/math.log(2) end
print(sqart(4))
morashsPeasant is flipping |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 09:50 PM |
@morash did that with 16, 64, and 128 Got 4, 6, 7 its kinda off |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 27 Sep 2015 09:51 PM |
inb4 someone posts the one bit of code from quake whatever number
or maybe they already have. I didn't exactly read the entire thread. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Sep 2015 09:56 PM |
| loadstring and bytecode, done. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 27 Sep 2015 10:12 PM |
for i,v in pairs (math) do getfenv()[i] = v end
print(sqrt(4))
> 2
I win. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Sep 2015 10:25 PM |
"return math.log(num)/math.log(2)" I don't know what made you think that would work, that just gets an exponent required to power 2 to get num...
2^(urcrap) = num |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 10:25 PM |
lol morash win, 5k posts!
morashsPeasant is flipping |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Sep 2015 10:26 PM |
| Also he/she doesn't win, considering he/she still IS using math.sqrt, it's the same function... |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 10:26 PM |
@cntkillme it would be 10^mycrap = aswer but no exponents (challange)
morashsPeasant is scripting? not even once! |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Sep 2015 10:27 PM |
| No it wouldn't, it would if you JUST did math.log(num) without the division |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Sep 2015 10:30 PM |
| Woops I lied, math.log is natural log so it would be e^x, not 10^x |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2015 10:31 PM |
Yep, dang natural logs. There is another function that is log10(blah) TILua
morashsPeasant is Dermon |
|
|
| Report Abuse |
|
|
| |
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 27 Sep 2015 10:35 PM |
function sqrt(value) local count=0 local current=1 while true do wait() if current>=value then break end current=current+2 count=count+1 end return count end
Maybe print(sqrt(9)) |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 28 Sep 2015 07:21 AM |
^doesnt work; same thing as dividing by 2 except not accurate?
so far, only person that met expectations and did it right is ticker |
|
|
| Report Abuse |
|
|
|
| 28 Sep 2015 07:28 AM |
number = 25
number2 = math.random(0,9e9) --find between 0 and 9 billion
while number2 * number2 ~= number do print(number2.."x"..number2.."="..number) end
|
|
|
| Report Abuse |
|
|
|
| 28 Sep 2015 07:30 AM |
--woops did something wrong
val = Instance.new("BoolValue") val.Parent = script
number = 25
number2 = math.random(0,9e9) --find between 0 and 9 billion
while true do wait() if number2 * number2 == number and val.Value == false then print("The square root of "..number.." is "..number2) val.Value = true end end |
|
|
| Report Abuse |
|
|