blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 06:17 PM |
Title is kinda hard to understand.
Let's say I have 95346. In base 10, I want a function that returns 5. If I had 30, for base 2, I'd want a function that returns 5 as well.
Would I have to make some logarithm function for every base? D: |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 06:19 PM |
| I would go out and buy a Magic eight ball. |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 06:24 PM |
"Would I have to make some logarithm function for every base? D:"
You could make the function for ONE base and make another function that converts any number from any base to any base and use that. |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 06:25 PM |
| why convert to bases when you can use one number? silly. |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Sep 2011 06:33 PM |
"why convert to bases when you can use one number? silly."
idk. You said you might have to make a function for each base. I suggested to just convert to bases instead. |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 06:34 PM |
ikr
I made a place value getter that works for any number in any base without conversion or strings or all that crap. |
|
|
| Report Abuse |
|
|
| |
|
Aaaboy97
|
  |
| Joined: 05 Apr 2009 |
| Total Posts: 6612 |
|
|
| 25 Sep 2011 06:39 PM |
local function power(a, b) local c = b local d = 0 while b < a do b = c^d d = d + 1 end return d - 1 end
print(power(30, 2), power(95346, 10)) > 5 5 |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Sep 2011 06:40 PM |
@WeDoItForTheLulz
I don't see how that's swearing. |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 06:40 PM |
| Aaaboy, srsly, lrn2giveacomprehensiblenametourvariablesplz |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 06:41 PM |
You're asking for the floor of a log in a given base...?
math.floor(1+ math.log( n ) / math.log(b) )
?
|
|
|
| Report Abuse |
|
|
Aaaboy97
|
  |
| Joined: 05 Apr 2009 |
| Total Posts: 6612 |
|
|
| 25 Sep 2011 06:42 PM |
| Julien, srsly, stoptrollingformackerel |
|
|
| Report Abuse |
|
|
Aaaboy97
|
  |
| Joined: 05 Apr 2009 |
| Total Posts: 6612 |
|
|
| 25 Sep 2011 06:42 PM |
@BlueTaslem
That's much better than mine, because i have no idea how to use log >.< |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 06:43 PM |
I'm not trolling...?!?!?
Seriously, giving letter names to your variables makes it look.. so ugly.. ;o |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 06:45 PM |
Simple rules for logs. (You'll need to know them eventually:)
a*log b = log(b^a) log[a] b / log[a] c = log[c] b
|
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 10:25 PM |
I don't understand how
math.log( n ) / math.log( b ) == x in b^x |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 10:27 PM |
| log( n ) / log( 2 ) == log2( n ) |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 10:28 PM |
| But I don't understand how that works. |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 10:29 PM |
| log( n ) / log( 2 ) == b^(n-2)? |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2011 10:29 PM |
| magic smoke stored in your cpu |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 10:30 PM |
| I simple do not understand what makes it return a value related to the one in the base you want. |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 10:31 PM |
| I'm not fit for being a scripter. I am ashamed. |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 25 Sep 2011 10:35 PM |
| This would be a perfect time for HotThoth to save the day. *COUGH* HOTTHOTH *COUGH* |
|
|
| Report Abuse |
|
|