Background
This is a continuation of my earlier challenge, where the task was to compute the shape of a sculpture obtained by dropping magnets into a huge pile.
Good news: the eccentric artist liked your work, and has another project for you. He still works with magnetic sculptures, but has decided to expand his art studio -- into space! His current method is to blast a single cube-shaped magnet into the orbit, and shoot other magnets at it to create a huge magnetic satellite.
Input
Your input is a finite list of 0
s and 1
s, given either in the native list format of your language, or a string. It is interpreted as a "blueprint" of a work of art, and is processed in order from left to right as follows.
You start with a single magnet floating at some integer coordinate of the 2D plane, and keep adding more magnets as per the directives. The directive 0
rotates the entire sculpture 90 degrees in the counter-clockwise direction. In the case of the directive 1
, the artist finds the leftmost column of the sculpture, and shoots a new magnet to it from below. The new magnet sticks to the bottom-most existing magnet in the column, and becomes a part of the sculpture. Note that the magnet does not stick to other magnets in the neighboring column, unlike in the earlier challenge; its speed is now astronomical!
Output
The artist wants to know whether the complete sculpture will fit into his garage (how he'll get it down from the orbit remains unclear). Thus, your output is the width and height of the sculpture, ordered from lower to higher. They can be given as a two-element list, a pair, or as a string separated by a comma.
Example
Consider the input sequence
[1,0,1,1,0,1,0,0,1,1]
To process it, we start with one magnet floating in space:
#
The first directive is 1
, so we shoot a new magnet from below:
#
#
The next directive is 0
, so we rotate the sculpture:
##
The next two directives are 1,1
, which means we'll shoot two magnets to the leftmost column:
##
#
#
Then, we rotate again and shoot once, as directed by 0,1
:
#
###
#
Finally, we rotate twice and shoot twice:
#
###
# #
#
The resulting sculpture has width 3
and height 4
, so we output [3,4]
.
Rules
You can give either a function or a full program. The lowest byte count wins, and standard loopholes are disallowed.
Test Cases
[1,0,1] -> [2,2]
[1,0,1,1,0,1,0,0,1,1] -> [3,4]
[1,1,0,1,1,0,1,0,1,1] -> [4,5]
[1,1,0,1,1,0,1,0,1,1,0] -> [4,5]
[1,0,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1] -> [3,3]
[0,1,0,1,1,1,1,0,0,1,0,1,0,0,1,1,0,1,0,1,0,0,1,1,0,1,0,0,0,0,1,0,1,0,1,1,0,0,1,1] -> [5,7]
[1,0,1,1,1,1,0,1,0,0,0,0,1,1,1,0,1,1,0,1,0,1,0,0,0,0,0,0,1,1,0,1,0,1,1,1,1,0,1,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,0,1,0,0,1,1,0,1,1,0,0,1,0,1,0,0,1,0,1,1,1,0,1,1,0,0,1,0,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0] -> [11,12]
[1,1,0,1,1,0,1,0,1,1,0]
return[5,4]
and not[4,5]
? The sculpture is rotated at the end. \$\endgroup\$