def aux(x): # in h we store the pre-calculated results for small dimensions h = {18:[6,6,6], 16:[8,8], 14:[8,6], 12:[6,6], 10:[6,4], 8:[8], 6:[6], 4:[4]} res = [] while x > 18: # as long as the remaining space is large, we put there tiles of size 8 res.append(8) x -= 8 if x not in h: print("no solution found") return [] return res + h[x] def tiles( x, y ): ax = aux(x) # split the x-dimension into tiles ay = aux(y) # split the y-dimension into tiles res = [ [ (x,y) for x in ax ] for y in ay ] for u in res: print(u) return res tiles( 90, 20 )
Standard input is empty
[(8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (6, 8), (6, 8), (6, 8)] [(8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (6, 6), (6, 6), (6, 6)] [(8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (8, 6), (6, 6), (6, 6), (6, 6)]