Xosceles
Pilot 2 · 2009-09-29 · by vexorian
Pilot 2 · 2009-09-29 · by vexorian · Brute Force, String Manipulation
Problem Statement
Problem Statement
Little Johnny loves triangles and loves ascii art, but above of all things, loves the character 'X'. His drive to mix these passions together has lead him to invent the Xosceles - Isosceles triangles made completely of 'X' characters. To draw a Xosceles, Little Johnny opens a text editor begins by typing "X" or "XX" (quotes for clarity) in the middle of the first line of the text document, he follows by typing 3 or 4 'X' characters in the following line, in such a way that the second line contains 2 more 'X' characters than the first one. He continues this process until he gets tired, making sure to align each line to the center (so that it forms an isoceles triangle).
Some example results of this process follow: (For convenience, '.' characters are used instead of whitespace):
Little Johnny has challenged you to draw a Xosceles using exactly xCount 'X' characters. Return aString[] that contains xCount characters and follows the rules stated above. The first element of your return value would represent the first line. All lines in the return must have the same length. Use '.' to represent whitespace, and make sure that your return value contains as little whitespace as possible. In case it is not possible to draw one of such triangles using xCount 'X' characters, return an empty String[] .
Some example results of this process follow: (For convenience, '.' characters are used instead of whitespace):
....X.... ...XXX... ..XXXXX.. .XXXXXXX. XXXXXXXXX ...XX... ..XXXX.. .XXXXXX. XXXXXXXX .X. XXX
Little Johnny has challenged you to draw a Xosceles using exactly xCount 'X' characters. Return a
Constraints
- xCount will be between 3 and 2550, inclusive.
Examples
0)
4
Returns: {".X.", "XXX" }
1)
6
Returns: {".XX.", "XXXX" }
2)
16
Returns: {"...X...", "..XXX..", ".XXXXX.", "XXXXXXX" }
3)
18
Returns: { }
It is not possible to make a triangle with 18 'X' characters.
4)
100
Returns: {".........X.........", "........XXX........", ".......XXXXX.......", "......XXXXXXX......", ".....XXXXXXXXX.....", "....XXXXXXXXXXX....", "...XXXXXXXXXXXXX...", "..XXXXXXXXXXXXXXX..", ".XXXXXXXXXXXXXXXXX.", "XXXXXXXXXXXXXXXXXXX" }
Submissions are judged against all 125 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Xosceles with a public method vector<string> draw(int xCount) · 125 test cases · 2 s / 256 MB per case