StackOverflow advised me to post here my issue. Although an alternative has been proposed, I would like to know why my few lines of code kinda stop working.
The script takes an empty array N and fills it randomly respecting only one rule : a slot can be filled only if previous, current and following slots are empty.
We want to know the filling rate for N -> infinity (obviously between 0.333 and 0.5).
My script might not be the best way to do that but it does not matter for my question is : why does it returns in ~2 minutes for N = 3.10^6 and still has not return for N = 3.5.10^6 and beyond ?
To compare, it takes roughly the same order of magnitude of time going from 10^6 to 2.10^6 to 3.10^6 (a few minutes).
I understand it’s the
del operation but what is happening that makes it suddenly so slow ?
The whole script is below, anyone can run it with
py script.py N
Sorry for my English & many thanks.
import sys import numpy as np from random import randint def main(arguments): N = int(sys.argv) # definissons notre ligne de maison : houses = *N emptySlot = list(range(0,N)) # counter = 1 while (len(emptySlot)>0): # on prend une maison vide possiblement habitable par un mysanthrope, au hasard. empt = randint(0, len(emptySlot)-1) houses[emptySlot[empt]] = 1 # on enlève cette maison de notre liste de possibilité # et éventuellement les maisons adjacentes si elles y étaient temp = emptySlot[empt] del emptySlot[empt] # on essaye d'enlever les autres si existes plus efficacement : if (0<=empt and empt<len(emptySlot) and emptySlot[empt] == temp+1): del emptySlot[empt] # comme on a viré l'index empt, ça décale. if (empt-1 >= 0 and emptySlot[empt-1] == temp-1): del emptySlot[empt-1] # pour l'inférieur, cela ne change rien occupancyRate = sum(houses) / N print(occupancyRate) if __name__ == '__main__': sys.exit(main(sys.argv[1:]))
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!