Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Shape Identifying Program

Your task is to build a program that identifies the shape of the input. The shapes to be identified can be any of the following:

Square

To be identified as a square, the source must have lines of all equal length, and the same number of lines as characters per line (newline characters excluded). An optional trailing newline is acceptable.

$_='
$_="
$_"'
;say

Rectangle

To be identified as a rectangle, the source must have lines of all equal length, but the number of lines does not match the number of characters per line (newline characters excluded). An optional trailing newline is acceptable. This can be either horizontal or vertical.

$_=
"no
t a
squ
are
";#
$_="but it
is still a
consistent
shape!";##

Triangle

To be identified as a triangle, the source must either start with one character, and each subsequent line must have one additional character (including the last), or after the first line, each subsequent line should have one character fewer until the last, which has only one.

$
_=
"So
this
"."".
shape;
$_="or
even,
this
way
!!
"

Mess

Anything that doesn't follow a consistent format as per the above, must be identified as a mess.

Rules

  • You may return any four consistent printable values to identify each shape.
  • Your source code must also adhere to one of the above shapes (no, not a mess).
  • A single trailing newline in your source is acceptable.
  • You can assume input does not contain any blank lines (including trailing newlines), is not empty, and does not consist only of newlines.
  • All shapes must have a height and width of>= 2, otherwise this is defined as a mess.
  • Standard loopholes are forbidden.
  • The shortest solution in bytes, in each language, wins.

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ Omit ?> should just be fine \$\endgroup\$ Commented Mar 23, 2018 at 10:02
  • \$\begingroup\$ This seems to return T for cccc\na\naa\ncccc Try it online! \$\endgroup\$ Commented Mar 23, 2018 at 12:44

AltStyle によって変換されたページ (->オリジナル) /