Skip to content

Instantly share code, notes, and snippets.

@ParrotParrot
Created December 3, 2018 19: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 ParrotParrot/67f62b4c8f8e07d52f52626e88a6bf9d to your computer and use it in GitHub Desktop.
Save ParrotParrot/67f62b4c8f8e07d52f52626e88a6bf9d to your computer and use it in GitHub Desktop.
import numpy as np
import random
grid = 50000
idlist = []
random.seed("send help")
solution = [random.randint(0,grid),random.randint(0,grid),random.randrange(1,1000),random.randrange(1,1000)]
solutionrange = [i for i in range(solution[0]+1, solution[0]+solution[2]+1)],[j for j in range(solution[1]+1, solution[1]+solution[3]+1)]
solutionid = random.randrange(0,100000)
print("Square that doesn't overlap is", solution, "with ID", solutionid)
file = open("Z:\output.txt", 'w')
for i in range(0,100000):
x,y,l,h,gottem = None, None, None, None, None
while not (gottem):
inx, iny = False, False
x,y,l,h = random.randint(0,grid), random.randint(0,grid), random.randrange(1,1000), random.randrange(1,1000)
if x+l > grid or y+h > grid: continue
for j in range (x+1,x+l+1):
if j in solutionrange[0]:
inx = True
break
for j in range (y+1, y+h+1):
if j in solutionrange[1]:
inx = True
break
if not (inx and iny): gottem = True
if i == solutionid: idlist.append("#"+str(i)+" @ "+str(solution[0])+","+str(solution[1])+": "+str(solution[2])+"x"+str(solution[3])+"\n")
else: idlist.append("#"+str(i)+" @ "+str(y)+","+str(x)+": "+str(h)+"x"+str(l)+"\n")
idlist[-1]= idlist[-1][:-1]
file.writelines(idlist)
file.close()
print("we big now")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment