Gegeven bouwblokken van lengte a en b wensen we een muur te bouwen die uit een aantal bouwlagen bestaat. Elke laag heeft hierbij dezelfde breedte. Bouw een klasse BouwProbleem, en programmeer in het bijzonder:

Voorbeeld

Tabblad 1

m = BouwProbleem(3, 5, 21)
print(m) #[3,5,21]
m += [5, 5, 3, 5, 3]
print(m.lagen()) #[[5, 5, 3, 5, 3]]
m += [5, 5, 3, 5, 3]
print(m.lagen()) #[[5, 5, 3, 5, 3], [5, 5, 3, 5, 3]]

b = BouwProbleem(3, 5, 21)
for laag in [[5, 3, 5, 5, 3]]:
	b += laag
print(b.lagen()) #[[5, 3, 5, 5, 3]]

m += b
print(m.lagen()) #[[5, 5, 3, 5, 3], [5, 5, 3, 5, 3], [5, 3, 5, 5, 3]]

for laag in  [3, [5, 5, 5, 3, 5]]:
	m += laag
print(m.lagen()) #[[5, 5, 3, 5, 3], [5, 5, 3, 5, 3], [5, 3, 5, 5, 3]]'




m = BouwProbleem(3, 4, 20)
print(m) #[3,4,20]

m += [3, 3, 4, 4, 3, 3]
print(m.lagen()) #[[3, 3, 4, 4, 3, 3]]
m += 10
print(m.lagen()) #[[3, 3, 4, 4, 3, 3]]

b = BouwProbleem(3, 4, 20)
for laag in [[4, 3, 3, 3, 3]]:
	b += laag
print(b.lagen()) #[]

m += b
print(m.lagen()) #[[3, 3, 4, 4, 3, 3]]
for laag in  [[4, 4, 3, 3, 3, 3], 2, [3, 4, 4, 5, 3, 3]]:
	m += laag
print(m.lagen()) #[[3, 3, 4, 4, 3, 3], [4, 4, 3, 3, 3, 3]]

Tabblad 2

m = BouwProbleem(2, 3, 9)
for laag in [[3, 2, 2, 2], [2, 2, 2, 3], [2, 2, 3, 2], [2, 2, 2, 3], [3, 3, 3]]:
	m += laag
print(m.lagen()) #[[3, 2, 2, 2], [2, 2, 2, 3], [2, 2, 3, 2], [2, 2, 2, 3], [3, 3, 3]]
print(m.conflicten()) #[(1, 2), (2, 2), (3, 1)]
print(sorted(m.mogelijke_lagen())) #[[2, 2, 2, 3], [2, 2, 3, 2], [2, 3, 2, 2], [3, 2, 2, 2], [3, 3, 3]]


m = BouwProbleem(3, 2, 18)
for laag in [[2, 3, 2, 3, 2, 2, 2, 2], [2, 2, 3, 2, 3, 2, 2, 2], [2, 2, 2, 2, 3, 3, 2, 2], [2, 2, 3, 3, 3, 2, 3]]:
	m += laag
print(m.lagen()) #[[2, 3, 2, 3, 2, 2, 2, 2], [2, 2, 3, 2, 3, 2, 2, 2], [2, 2, 2, 2, 3, 3, 2, 2], [2, 2, 3, 3, 3, 2, 3]]
print(m.conflicten()) #[(0, 5), (1, 4), (2, 2)]
print(sorted(m.mogelijke_lagen())) #[[2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 3, 3], [2, 2, 2, 2, 2, 3, 2, 3], [2, 2, 2, 2, 2, 3, 3, 2], [2, 2, 2, 2, 3, 2, 2, 3], [2, 2, 2, 2, 3, 2, 3, 2], [2, 2, 2, 2, 3, 3, 2, 2], [2, 2, 2, 3, 2, 2, 2, 3], [2, 2, 2, 3, 2, 2, 3, 2], [2, 2, 2, 3, 2, 3, 2, 2], [2, 2, 2, 3, 3, 2, 2, 2], [2, 2, 2, 3, 3, 3, 3], [2, 2, 3, 2, 2, 2, 2, 3], [2, 2, 3, 2, 2, 2, 3, 2], [2, 2, 3, 2, 2, 3, 2, 2], [2, 2, 3, 2, 3, 2, 2, 2], [2, 2, 3, 2, 3, 3, 3], [2, 2, 3, 3, 2, 2, 2, 2], [2, 2, 3, 3, 2, 3, 3], [2, 2, 3, 3, 3, 2, 3], [2, 2, 3, 3, 3, 3, 2], [2, 3, 2, 2, 2, 2, 2, 3], [2, 3, 2, 2, 2, 2, 3, 2], [2, 3, 2, 2, 2, 3, 2, 2], [2, 3, 2, 2, 3, 2, 2, 2], [2, 3, 2, 2, 3, 3, 3], [2, 3, 2, 3, 2, 2, 2, 2], [2, 3, 2, 3, 2, 3, 3], [2, 3, 2, 3, 3, 2, 3], [2, 3, 2, 3, 3, 3, 2], [2, 3, 3, 2, 2, 2, 2, 2], [2, 3, 3, 2, 2, 3, 3], [2, 3, 3, 2, 3, 2, 3], [2, 3, 3, 2, 3, 3, 2], [2, 3, 3, 3, 2, 2, 3], [2, 3, 3, 3, 2, 3, 2], [2, 3, 3, 3, 3, 2, 2], [3, 2, 2, 2, 2, 2, 2, 3], [3, 2, 2, 2, 2, 2, 3, 2], [3, 2, 2, 2, 2, 3, 2, 2], [3, 2, 2, 2, 3, 2, 2, 2], [3, 2, 2, 2, 3, 3, 3], [3, 2, 2, 3, 2, 2, 2, 2], [3, 2, 2, 3, 2, 3, 3], [3, 2, 2, 3, 3, 2, 3], [3, 2, 2, 3, 3, 3, 2], [3, 2, 3, 2, 2, 2, 2, 2], [3, 2, 3, 2, 2, 3, 3], [3, 2, 3, 2, 3, 2, 3], [3, 2, 3, 2, 3, 3, 2], [3, 2, 3, 3, 2, 2, 3], [3, 2, 3, 3, 2, 3, 2], [3, 2, 3, 3, 3, 2, 2], [3, 3, 2, 2, 2, 2, 2, 2], [3, 3, 2, 2, 2, 3, 3], [3, 3, 2, 2, 3, 2, 3], [3, 3, 2, 2, 3, 3, 2], [3, 3, 2, 3, 2, 2, 3], [3, 3, 2, 3, 2, 3, 2], [3, 3, 2, 3, 3, 2, 2], [3, 3, 3, 2, 2, 2, 3], [3, 3, 3, 2, 2, 3, 2], [3, 3, 3, 2, 3, 2, 2], [3, 3, 3, 3, 2, 2, 2], [3, 3, 3, 3, 3, 3]]

Tabblad 3

m = BouwProbleem(2, 3, 9)
print(sorted(m.alle_oplossingen(3))) #[[[2, 2, 2, 3], [3, 2, 2, 2], [2, 2, 2, 3]], [[2, 2, 3, 2], [3, 3, 3], [2, 2, 3, 2]], [[2, 2, 3, 2], [3, 3, 3], [2, 3, 2, 2]], [[2, 3, 2, 2], [3, 3, 3], [2, 2, 3, 2]], [[2, 3, 2, 2], [3, 3, 3], [2, 3, 2, 2]], [[3, 2, 2, 2], [2, 2, 2, 3], [3, 2, 2, 2]], [[3, 3, 3], [2, 2, 3, 2], [3, 3, 3]], [[3, 3, 3], [2, 3, 2, 2], [3, 3, 3]]]

m = BouwProbleem(2, 5, 19)
print(sorted(m.alle_oplossingen(1))) #[[[2, 2, 2, 2, 2, 2, 2, 5]], [[2, 2, 2, 2, 2, 2, 5, 2]], [[2, 2, 2, 2, 2, 5, 2, 2]], [[2, 2, 2, 2, 5, 2, 2, 2]], [[2, 2, 2, 5, 2, 2, 2, 2]], [[2, 2, 5, 2, 2, 2, 2, 2]], [[2, 2, 5, 5, 5]], [[2, 5, 2, 2, 2, 2, 2, 2]], [[2, 5, 2, 5, 5]], [[2, 5, 5, 2, 5]], [[2, 5, 5, 5, 2]], [[5, 2, 2, 2, 2, 2, 2, 2]], [[5, 2, 2, 5, 5]], [[5, 2, 5, 2, 5]], [[5, 2, 5, 5, 2]], [[5, 5, 2, 2, 5]], [[5, 5, 2, 5, 2]], [[5, 5, 5, 2, 2]]]