Floorsort-Algorithm

Arrange n number of different sized rectangles in such a way, so the resulting square encompassing all rectangles is as small as possible.

Pseudocode below

generate n number of rectangles with random height and width

L = sqrt(area of all rectangles) * L-factor

sort rectangles by height, then width

for n number of rectangles:

if height of next rectangle smaller than previous:

append new transition point for next row

if next rectangle trespasses a transition point:

update current height

append new transition point for next row

if current position <= L (or 0):

lay down current rectangle

else:

switch direction of rectangle laying

jump to next row


💀 Made with Skeleton — UI Toolkit for Svelte + Tailwind 💀