Problem 1908. Equilibrium
Is this tower of blocks going to fall?
Description
Given a stacking configuration for a series of square blocks, your function should return true if they are at equilibrium and false otherwise.
The block configuration for N blocks is provided as a input vector x with N elements listing the xcoordinates of the leftside of each block. The blocks are square with side equal to 1 (so the ith block left side is at x(i) and its right side is at x(i)+1). The ycoordinates of each block are determined implicitly by the order of the blocks, which are dropped "tetrisstyle" until they hit the floor or another block.
All blocks are identical (same dimensions and mass) and perfectly smooth (friction is to be disregarded).
Intermediate positions may be unstable. You are only required to determine whether the final configuration is stable.
Examples:
Example (1)
x = [0 0.4];
The first block bottomleft corner is at (0,0) and the second block falls on top of it, with its bottomleft corner at (0.4 1). This configuration is stable so your function should return true.
Example (2)
x = [0 0.6];
The first block bottomleft corner is at (0,0) and the second block falls on top of it, with its bottomleft corner at (0.6 1). This configuration is unstable (the second block will fall) so your function should return false.
Example (3)
x = [0 1.5 0.6];
The three block bottomleft corner coordinates are (0,0) (1.5,0) and (0.6,1). This configuration is stable so your function should return true.
Example (4)
x = [0 .9 .9 zeros(1,5)];
This configuration is unstable, but note that if instead of five we add a few more blocks on top of this at the 0 position that will keep the tower from falling!
Example (5)
x = cumsum(fliplr(1./(1:8))/2);
This configuration is stable (see the classic optimal stacking solution) so your function should return true.
Display
If you wish, you may display any given block configuration x using the code below:
clf; y=[]; for n=1:numel(x), y(n)=max([0 y(abs(x(1:n1)x(n))<1)+1]); end h=arrayfun(@(x,y)patch(x+[0,1,1,0],y+[0,0,1,1],rand(1,3)),x,y); text(x+.5,y+.5,arrayfun(@num2str,1:numel(x),'uni',0),... 'horizontalalignment','center');
Visit Block canvas for a related Cody problem.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers3
Suggested Problems

1584 Solvers

27 Solvers

Criss_Cross_000 : Unique elements in a Square array
8 Solvers

Return a list sorted by number of consecutive occurrences
352 Solvers

576 Solvers
More from this Author38
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!