#math problem for game dev
79 messages · Page 1 of 1 (latest)
- Wait patiently for a helper to come along.
- Once someone helps you, say thank you and close the thread with:
+close
- Feel free to nominate the person for helper of the week in #helper-nominations
for example if N is 17 and B is 2
then the largest number would be 2^0+2^1+2^2+2^3
Let (S = 1 + b + \ldots + b^k).
Then
\begin{align*}
b S &= b + \ldots + b^k + b^{k + 1} \
S - 1 + b^{k + 1} &= b^1 + \ldots + b^k + b^{k + 1}
\end{align*}
so (b S = S - 1 + b^{k + 1} ). Solving for (S) yields
[S = \frac{b^{k + 1} - 1}{b - 1} .]
So we want the largest (k) such that
[\frac{b^{k + 1} - 1}{b - 1} \leq N.]
yep decimals also work for b>=2
invariance.
given (N) and (b), you can solve (\frac{b^{k + 1} - 1}{b - 1} = N) (using a logrithm at the end)
lol i actually got that formula too (the end formula)
invariance.
maybe I was mistaken that it didn’t work for b<2
then you can floor to get your result
yeah it should work fine
hm
k
i actually only know algebra 2 so some of this stuff is beyond me but surprisingly my knowledge on different number bases helped me in this case
cause numbers are essentially the same idea
you want the biggest number of the form 111...111 in base b, you mean?
no no
wdym then?
like for b = 3 and n = 26 i would want
3^0+3^1+3^2
something i don’t get is
(1.1^4-1)/(0.1) is not equal too 1.1^0+1.1^1+1.1^2+1.1^3?
shouldn’t it be equal
,w 1.1^0+1.1^1+1.1^2+1.1^3
,w (1.1^4-1)/(0.1)
they are equal
(idk why you're saying they're not, but remember that === is very unreliable with floating point numbers)
oh i’m stupid
i forgot to add 1.1^3
anyways, why not I might use it, how would this problem be solved for 0<b<1
would it work the same?
the infinite series converges
invariance.
yea what about different fractions?
so the series sums to 2
it converges if and only if |b| < 1
i see
let me try to get some code working for it once done I’ll close this
btw let’s say it starts at b^2+b^3…
it would be the equivalent to the answer of the same problem starting at b^0
but the answer is divided by b^2
right?
(b^2 + b^3 + \ldots + b^k = b^2 (1 + \ldots + b^{k - 2}))
yea
invariance.
btw the whole idea of this is that a price of an upgrade in my game scales multiplicatively but the game will eventually reach a point where that upgrade must be bought really fast
and this just calculates that in bulk
I had guessed that
it's neat that you're making games and finding an application for this stuff at the middle-school level
thanks!
honestly it’s nice that I covered logarithms in school
since i have been finding lots of uses
ok so this works but for technical reasons I also need to find k and return that too
how would I do that
noooo it doesn’t work ):
yea honestly not sure how to approach this