Guest User

Untitled

a guest
Feb 19th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. Bin Packing Lab
  3. Problem Based Intro to CS
  4. Created By: Eric Griswold
  5. """
  6.  
  7. def getFile(filename):
  8.     """getFile imports a file and takes the string of numbers and splits
  9.    them into a list and then sorts the list. """
  10.     blockList = []
  11.     for line in open(filename):
  12.         line = line.split()
  13.     blockList = sorted(blockList, reverse = True)
  14.     return blockList  
  15.  
  16. def squareSize(size):
  17.     bin = [[0 for col in range(size)] for row in range(size)]
  18.    
  19. def displayBin(bin, size):
  20.     for row in range(size):
  21.         for col in range(size):
  22.             print(bin[row][col], end = ' ')
  23.         print()
  24.    
  25.  
  26.  
  27. def binput(bin, size, r, c):
  28.     for a in range(r, r+size):
  29.         for b in range(c, c+size):
  30.             bin[a][b] = int(size)
  31.     return bin
  32.        
  33.                  
  34. def isSpaceFree(bin, r, c, size):
  35.     if r + size >= len(bin):
  36.         return False
  37.     if c + size >= len(bin):
  38.         return False
  39.     for i in range(size):
  40.         for j in range(size):
  41.             if bin[r + i][r + j] != 0:
  42.                 return False
  43.     return True
  44.  
  45. def pack(bin, size):
  46.     for x in boxes:
  47.         for r in range(0, len(bin)-1):
  48.             for c in range(0, len(bin)-1):
  49.                 if(isSpaceFree(bin, r, c, size)):
  50.                     bin2 = binInput(bin, size, r, c)
  51.         return bin2                    
  52.                
  53. def main():
  54.     filename = input('Enter File name: ')
  55.     size = input('Please enter size of bin: ')
  56.     getFile(filename)
  57.     bin = squareSize(size)
  58.     displayBin(pack(bin, blockList), len(bin))
Add Comment
Please, Sign In to add comment