Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from itertools import permutations
- import numpy as np
- import random
- def bonus(a,b,c,x,y,z,f,g):
- return (1+a/250) * (1+b/250)**2 * (1+c/250)**3 * (1+x/250)**4 * (1+y/250)**5 * (1+z/250)**6 * (1+f/250)**7 * (1+g/250)**8
- start = time.time()
- arg_list = [np.zeros(8)]
- bonus_list = [1]
- args = np.zeros(8)
- iterindices = list(permutations(range(8), 2))
- b_array = np.zeros(len(iterindices))
- step = 8
- for levels in range(8, 8000, step):
- running = True
- new_levels = step
- while new_levels > 0:
- args[random.sample(range(8), 1)[0]] += 1
- new_levels -= 1
- a, b, c, x, y, z, f, g = args
- bon = bonus(a, b, c, x, y, z, f, g)
- max_bonus = bon
- while running:
- args_copy = np.vstack([args for _ in range(len(iterindices))])
- for n, (i, j) in enumerate(iterindices):
- if args_copy[n, i] > 0:
- args_copy[n, i] -= 1
- args_copy[n, j] += 1
- a, b, c, x, y, z, f, g = args_copy[n,:]
- b_array[n] = bonus(a, b, c, x, y, z, f, g)
- if b_array.max() > max_bonus:
- max_bonus =b_array.max()
- swap = iterindices[b_array.argmax()]
- args[swap[0]] -= 1
- args[swap[1]] += 1
- else:
- running = False
- arg_list.append(args)
- bonus_list.append(max_bonus)
- end = time.time()
- print(end-start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement