You might enjoy a classic quant finance interview question “can you pack 53 bricks of dimensions 1x1x4 into a 6 x 6 x 6 box?” See section 2.3 of Xinfeng Zhou’s “A practical guide to quantitative finance interviews” (https://usermanual.wiki/Document/Practical20Guide20To20Quantitative20Finance20Interview.604244935.pdf) for an answer.

]]>1 2

3 4

be the upper left corner of the board. We can draw a Hamiltonian cycle through all the cells except the corner cell 1, so that the cycle goes: … 3 4 2 … If 1 is close to 4 we can just insert it on either side of 4, so suppose 1 > 4 by more than 1 inch. Then 2 and 3 are both larger then 4 and smaller than 1. We can put either 1 or 4 between 2 and 3 equally well, so we just need to find a place for the other one. If the cell coming before 3 in the cycle is smaller than 3, we can insert 4 between them, and if it’s larger, we can insert 1 between them, so the final order will be … 1 3 4 2… or …. 4 3 1 2…. ]]>