Skip to content

Instantly share code, notes, and snippets.

@SalahAdDin
Last active May 11, 2017 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SalahAdDin/0b5b0b121ad4f1996d49 to your computer and use it in GitHub Desktop.
Save SalahAdDin/0b5b0b121ad4f1996d49 to your computer and use it in GitHub Desktop.
Album problem's implementation.
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