Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Pages: 1
Alternate title: Random choice without replacement.
Can you design the best vending machine that works for large n?
Offline
equal distribution the whole time! Chance to get each remaining item is always 1 in [items remaining] !
Offline
Is there any elegant solution to this problem for large n (number of items in the machine)?
no; if you need equal chances for each, you NEED the continuous random switching.
suddenly random sig change
Offline
but can you do better then n! size?
Offline
Here's my attempt
Edit: Since I did a boost before letting the player in the machine, the gap between the portal and the gravity block could be removed.
Edit 2: nvm slabdrill already did it lol
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)
Very inactive, maybe in the future, idk.
Offline
I guess if you can do it in real life programming then you can do it in EE, maybe by switching the selected slot with the last slot that hasnt been opened so all filled slots are grouped together, and using a lookup table to get the rewards from the 'reward id', althought this is massively overcomplicating it...
Might try to do this later, althought it probably would never be worth it unless you had thousands of rewards
Edit: I think using this technique would mean you could do it in O(log n) time, but with a massive amount of overhead
Edit 2: Here is an algorithm for how to do it that should be fully implementable in EE which I think is O(log n):
items <- array of items in vending machine
n <- no of items - 1
slots <- array of numbers 0 to n
To get item:
item <- remove last item from slots
selected <- false
while not selected:
i <- random number of the same number of bits as is needed to store n
if i = n:
selected <- true
else if i < n:
switch item and i in slots
selected <- true
n <- n - 1
return item in items
Offline
yeah its easy to use code but can you use ee-block-code?
Offline
I'm creating one that's should be O(log n) time and smaller than lukes (cant guarantee faster though) and more switch ID-friendly (~3n + 2*log2(n) as opposed to ~(n+3)log2(n))
thanks to muffin for idea, luke pls get your bot up
i guess the big thing is that my idea is O(n) worst-case but i think its O(log n) average-case so i should be fine
suddenly random sig change
Offline
luke pls get your bot up
Sorry, BT man was in fixing my phone line, should be back up now
Edit: Seems it wasnt that... I think it was something I updated causing it to crash whenever I closed the console, fixed now
Offline
Sort of finished my vending machine thing :
PWRG9TzKGNcEI
It seems that the resetters occasionally dont work, and im not sure why, so ill fix this when I know how to...
And this solutions complexity is:
O(log n) in time
O(n log n) in switches
O(n) in portals
It fills probably 2/3 of a large world, and contains 32 items (coins)
It works by using a second table of item ids, which means you can basically move around the items in a list, this means that rather than leaving gaps when you take an item, you can keep it so that all remaining items are at the start of the list, and all used items are at the end. This means that you can do the trial and error technique, but with the minimum number of bits to be able to select every item, which means there is always a chance of >50% of picking a new item, so you rarely get rerolls, (and have an upper bound on the average number of rerolls, which is 2)
Offline
this is very happy and I like to see it! I appriecate your help in making cool stuff!
Offline
Pages: 1
[ Started around 1738280551.5283 - Generated in 0.071 seconds, 12 queries executed - Memory usage: 1.54 MiB (Peak: 1.71 MiB) ]