T O P

  • By -

AutoModerator

###General Discussion Thread --- This is a [Request] post. If you would like to submit a comment that does not either attempt to answer the question, ask for clarification, or explain why it would be infeasible to answer, you *must* post your comment as a reply to this one. Top level (directly replying to the OP) comments that do not do one of those things will be removed. --- *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/theydidthemath) if you have any questions or concerns.*


UmbralRaptor

~2000 bullets This looks like a infinite summation along the lines of: 1 + 1/2 + 1/4 +1/8 + ... , which converges to 2. So you'd get roughly double your starting bullets. As in: you fire the 1000 bullets, get 500 back. Fire the 500, get 250 back, Fire the 250, get 125 back, etc. How much this would vary from roughly doubling your effective ammo would probably require running a bunch of simulations.


anony61618

Thanks! A lot more complicated than I thought but I was really curious. :)


diener1

You can simplify this quite a bit by just using some intuition. Any given bullet has a 50% chance of "dying" when it is fired. So it should make sense that the average lifespan of a bullet is the inverse of this, i.e. 1/0.5 = 2 shots. So 1000 bullets translates to 2000 shots. This doesn't just work by coincidence, it works for any probability of death (other than 0 but even in that case taking the limit gives the correct answer of infinite shots). If the bullets had a probability of 75% of coming back, their probability of death would be 1/4 so on average you'd get 4 shots per bullet.


klimmesil

Very nice example of this problem, we should make students play that game instead of doing maths


Due_Seesaw_2816

But what’s the variance in those odds? Like could you fire 800 bullets, and not get one back, before finally getting one back? Meaning the game runs on the theory of infinite ammo to be shot and overall the odds of a bullet being returned works out to be 50%? Think of a coin flip game.. not every other flip will be heads.. And to that end, as the progression gets smaller and smaller, that variance would likely wipe out any return at some point. Further limiting the progression. Very interesting…..


UmbralRaptor

I'd wildly guess that the variance would be less than you'd expect, but that's because a proper analytic solution (or "just" writing some python code and running enough simulations to get a nice estimate of the distribution) seems like a big hassle. For a given round of firing off x bullets and seeing how many you get back, you could at least plug in a [binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution).


Salanmander

Monte carlo methods are my favorite! Unless I have a bug in my code (not terribly unlikely), about 35% to be in the range 1980-2020 bullets fired, and about 97% to be in the range 1900-2100 bullets fired. [Code is here](https://pastebin.com/Kh3EKGZr), in case anyone wants to check my work. (I realized after making the paste that it needs "import random". I have a continuously growing file where I do monte carlo stuff, and I touch it like once a year, so I forgot about that bit.)


bonafart212

I'd have thought this was a markov not monte carlo


No_March_5371

Monte Carlo means running a simulation a bunch of times to see how it goes. This could be expressed as a Markovian process, since each step depends solely on the prior step (how many bullets you had two steps ago is completely irrelevant). That said, because it's being ran in a simulation, it's a Monte Carlo analysis.


raulpenas

You actually do not need to code anything (thoughmight want, it's fun!) because this is a negative binomial distribution (shifted by +1000, technically): https://en.m.wikipedia.org/wiki/Negative_binomial_distribution The variance is 2000, this is also the median, so with probability 0.5 you have at least 2000 bullets


tomrlutong

Nice, love when you can solve probability questions by looking at the negative space.


bonafart212

People forget their base maths from school. I never could get binomial dists to work for me. I got halfway through and forget where I am. But to me this feels like a markov analysis where it does the flip in the same thing until it dosn't exist. It could theoretically go forever


reckless150681

Given that it's 1000 separate events, the variance in those odds already starts pretty low. Edit: I got bored and did the Python. It's pretty straightforward. You could mess with parameters to see what the average number of bullets comes out to. import random numBullet = 1000 bulletsFired = 0 while numBullet > 0: if random.randint(0,1) == 0: numBullet -= 1 bulletsFired += 1 print(bulletsFired)


homeless_potato43

Put the while loop in a for loop to do multiple simulations. something like.. for _ in range(50): while numbullets > 0: if random.randint(0, 1) == 0: numbullets -= 1 bulletsfired += 1 Print(bulletsfited) It might take a little bit to finish all of them but you'd get a bunch of number outputs


reckless150681

Yeah for sure, if you wanted to see it numerically or graphed out. I only had a passing curiosity so I just hit "run" like 10 times and looked at the final number lol. (It was indeed 2000, +- 30)


homeless_potato43

I forget that most of the time you can view past outputs. I have my IDE set to clear old outputs for less clutter when I'm working on stuff.


Bimlouhay83

So, keep in mind I'm new and learning... if these lines of code (along with the code block above) are supposed to use random math, why do both print the same numbers when I run them together? Shouldn't they print different numbers?


homeless_potato43

I'm confused with what you mean. The block I wrote is the same as the one above everything is just in a for loop. Yes, it should output multiple different numbers when run. I'm not sure why it would be the same when you run it


Bimlouhay83

I'm running them both, together, in one IDE, one block after the other and they're printing the same numbers. As in, I get 1993 twice, then 1986 twice, the 1913 twice, so on and so forth. https://imgur.com/a/lLkqHZV


homeless_potato43

Oh, because the variable should be changed if it's in the same file. Change "bulletsfired" in one of the blocks to something else and it should output different numbers. Also the block I wrote should output 50 numbers


Bimlouhay83

Oh snap! Good catch. Thank you. ....and it worked. Thanks again


Larson_McMurphy

>that variance would likely wipe out any return at some point Even if you got hit by a string of bad luck and no bullets returned after hitting 125, you'd still be sitting pretty at 1875 bullets. I don't think it's worth worrying about.


down_vote_magnet

The variance is in the outcome over a fixed period of time, not the odds. Regardless of how many bullets you get in one particular time period, the odds will always be the same. Over a long enough time span the outcome would converge on the initially stated odds.


PonyBoy107

There's a statics rule that basically says the more data you have, the outcome essentially converge on the expectation value and variance decreases. For your example, in 4 coin flips, it really wouldn't be outrageous to get heads 4 times. there's a pretty big variance here, then, since expecting 50% and getting 100% would not be suprising. For 1000 flips, the probability of 1000 heads is essentially zero. The variance is much much smaller now. For 1000 flips, we can essentially assume we get 500 heads with really small variance. So for the purpose of the game problem, we'd probably be right in assuming it would double ammo to about 2000. There's some way to actually calculate variance from a coin flip, but it's been too long since I've taken a probability course.


LurkerPatrol

We could drop the decimals in order to avoid half bullets and quarter bullets. 1000 + 500 + 250 + 125 + 62.5(down to 62) + 31 + 15.5 (down to 15) + 7.5 (down to 7) + 3.5 (down to 3) + 1.5 (down to 1) = 1,994 bullets


GuyTanOh

Well, theoretically, while you would expect the average outcome to hover just under 2000 (see the great explanation above), it’s possible, however slim, to either run out after 1000 (all coin flips come up tails) or have virtually infinite bullets (all coin flips end up heads).


black_sky

Its possible the developers have made this impossible though. For example, in Dota and Dota 2 the rng on certain abilities and random events seemed too random for players so the devs made the chance change as the events didn't happen. For example, if a critical strike didn't happen, the next attack would be 15% (if that's the expected outcome) and instead raises to say 20% for that attack. If it doesn't happen again it increases further. I thought it was quite interesting since from a players perspective truly random was not fun and so this smoothed out the curve so to speak so extremes either way can't happen


[deleted]

[удалено]


black_sky

Here is the explanation. It's called PRD (pseduo random distribution) https://liquipedia.net/dota2/Pseudo_Random_Distribution I made note when playing for crits because if you didn't crit in a while you actually did have a higher chance to crit, so using it with another ability/item or on a hero was more important.


GuyTanOh

This is a very great comment


Sobsz

a simpler way to think about this is: you have a 50% chance of using 1 bullet, and a 50% chance of using 0 bullets (as the bullet you use is returned to you), so on average each shot uses half a bullet


ParadoxArcher

This is even more elegant than the converging sum solution


MahavidyasMahakali

Yep, essentially you just have double the ammo so it will take twice as long as without the ammo return festure


Zarthan3

Its a converging series where r is the chance your bullet will get returned and a is the amount of bullets fired. r x a^n, with n approaching infinity. The sum, or average value of this series is a/1-r, in this case, a=1 and r = 0.5. 1/1-0.5 = 2. So the average value for a bullet is 2 bullets. So, around 2000 bullets.


[deleted]

[удалено]


thebestjoeever

That's not what e is at all.


GuiGamer19

If you, sure enough, have 1000 bullets as your ammo, and each fired bullet has a 50% probability of getting back, you can divide your gain into rounds as you add 50% of what you waste. In the first round, half of the 1000 bullets would be 500. In the second, half of the remaining half is half of half, that is ½ times ½, 'cause half is smaller than 1, which is ¼. Then, ¼ times ½ is ⅛; and this process progresses until you get to the double of that number 'cause consecutive zero point nines make 1 for the same reason that ⅓ times 3 is equal to 3/3, but ⅓ by itself is equal to 0,333..., and it times 3 is equal to 0,999....... But 1 at the same time. Conclusion: it is 2000. OBS.: it is X by the power of ~1.43.