Anlysis
Before explaining the approach, let’s first confirm our assignment requirements.
| Assignment Requirements |
The assignment brief is already quite clear. In the previous assignment, we essentially resolved the common hurdles when using the basic Houdini Python API, and this time we hardly need any new APIs. Therefore, this post will mainly explain the implementation approach.
Because we ultimately want the soldiers’ formation to be neat—and preferably a square—we should analyze the problem first. The formula can be split into two parts: compute the Unit first, then compute the Soldiers Number. Our implementation follows the same idea.
| Decompose The Formula |
Step 1: Generate the Unit. Its geometric meaning is straightforward: a formation with Base rows by Base columns of soldiers.
Step 2: Since we want the final result to be organized as an array of Units with M rows by N columns, we need a way to determine how many Units are required to assemble the final square formation. The answer is intuitive:
Once we obtain the value of Total Units, we naturally have M × N = Total Units. We want the final array to be as close to a square as possible (for better aesthetics), so M and N should be as close as they can be, and both will be near √(Total Units). Ideally, Total Units has an integer square root.
Since we already know Unit = Base², we can conclude that Total Units can indeed yield an integer square root.
At this point, the basic algorithmic idea is clear: implement it according to the assignment requirements and generate the result.
Tips: When implementing this in Houdini, I like to treat both “Soldier” and “Unit” as discrete entities. In my implementation, one “Geo” serves as a “Unit,” and each “Shape” inside that “Geo” is treated as a “Soldier.” This hierarchy makes the overall implementation clearer.





