Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Bin Packing Lab
- Problem Based Intro to CS
- Created By: Eric Griswold
- """
- def getFile(filename):
- """getFile imports a file and takes the string of numbers and splits
- them into a list and then sorts the list. """
- blockList = []
- for line in open(filename):
- line = line.split()
- blockList = sorted(blockList, reverse = True)
- return blockList
- def squareSize(size):
- bin = [[0 for col in range(size)] for row in range(size)]
- def displayBin(bin, size):
- for row in range(size):
- for col in range(size):
- print(bin[row][col], end = ' ')
- print()
- def binput(bin, size, r, c):
- for a in range(r, r+size):
- for b in range(c, c+size):
- bin[a][b] = int(size)
- return bin
- def isSpaceFree(bin, r, c, size):
- if r + size >= len(bin):
- return False
- if c + size >= len(bin):
- return False
- for i in range(size):
- for j in range(size):
- if bin[r + i][r + j] != 0:
- return False
- return True
- def pack(bin, size):
- for x in boxes:
- for r in range(0, len(bin)-1):
- for c in range(0, len(bin)-1):
- if(isSpaceFree(bin, r, c, size)):
- bin2 = binInput(bin, size, r, c)
- return bin2
- def main():
- filename = input('Enter File name: ')
- size = input('Please enter size of bin: ')
- getFile(filename)
- bin = squareSize(size)
- displayBin(pack(bin, blockList), len(bin))
Add Comment
Please, Sign In to add comment