Last active
May 11, 2017 07:27
-
-
Save SalahAdDin/0b5b0b121ad4f1996d49 to your computer and use it in GitHub Desktop.
Album problem's implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import math | |
import random | |
def get_new_album(n): | |
i = 1 | |
# album = [[0 for x in range(n)] for x in range(n)] | |
album = [0 for x in range(n)] | |
# print(album) | |
return album | |
def fill_album(n, album): | |
y = 0 | |
c = 0 | |
while c < n: | |
print(c) | |
y += 1 | |
u = random.uniform(0, 1) | |
l = math.floor(n * u) + 1 | |
print("u: %f, n*u: %f, l: %d" % (u, n * u, l)) | |
# print(album[l-1]) | |
print(album) | |
if album[l - 1] == 0: | |
album[l - 1] = 1 | |
c += 1 | |
return y | |
def main(n, m): | |
print("Iniciando la simulación...") | |
i = 1 | |
s = 0 | |
while i <= m: | |
album_sim = get_new_album(n) | |
y = fill_album(n, album_sim) | |
s += y | |
i += 1 | |
prom = s / m | |
print("El promedio es: ", prom) | |
if __name__ == "__main__": | |
main(2, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment