(Note: I'm not in the army so feel free to correct me if my formation is wrong, but I will not be changing the question. I will change any terminology mistakes though, because I'm trying to avoid air-cadet-specific wording choices)
(Note: this follows the standards for Canadian Air Cadets, not any actual army thing)
Challenge
Given some configurations for a squadron, output what it should look like.
You will use 1 non-whitespace character to represent people.
Configuration
The configuration will consist of a mandatory non-empty list, a mandatory positive integer, and an optional positive integer. The list represents the number of people per "squad", the mandatory integer represents the maximum number of rows, and the optional integer represents the number of "squads" in the squadron; in other words, the length of the list.
Each squad looks like this (without the commanders):
X X X X X
X X X X
X X X X
This would be a squad with 13 people in 3 rows.
A squad must be strictly wider than it is tall, unless it's a single person, in which case it's 1 × 1. It must also be as tall as possible (within the restriction for the number of rows); that is, once it is one larger than a perfect square, it should form another row. An exception is that when there are 5 people, it should still be a single row.** The gap is always placed in the second column from the left, starting from the second row and moving downwards. For example, with 28 people and 5 rows maximum:
X X X X X X
X X X X X
X X X X X
X X X X X X
X X X X X X
Then, after the squad is formed, a commander is to be placed 2 rows above and below the squad, in the exact centre. For odd width squads:
X
X X X X X
X X X X X
X X X X X
X
And for even width squads:
X
X X X X
X X X X
X X X X
X
Hopefully you now understand how an individual squad is formed. Then, to form a squadron, each squad has 7 blank columns between it. For example, with a maximum row count of 3 and three squads of size 15, 16, and 17:
X
X X X
X X X X X X X X X X X X X X X X X
X X X X X X X X X X X X X X X
X X X X X X X X X X X X X X X X
X X X
Then, in the final step, a commander is placed two rows above the row of front commanders, directly in the centre of the squadron, to the left if it has even width. In the example above, that would be the X
at the very top.
The final output may contain trailing whitespace on each line and an optional trailing newline.
Here's a reference implementation: Try It Online! (Python 3)
Input
Input will be given in any flexible format with the 3 components listed above: list, int[, int]
.
Rules
- Standard loopholes apply
- Output must be in this exact format (of course, you may choose the character to use)
- Newline may be CR, LF, or CRLF
- Trailing whitespace is allowed
- Trailing newline is allowed
**Except our squadron's Flag Party formed a 3x2 pseudorectangle :P