Revision 270d1f5c-8dfb-4825-8d9c-96b633bae88a - Code Golf Stack Exchange
# [Jelly], 32 bytes
,U⁼€JẸ,E
L€ÇæAFLƲƊ
ỴµZL«L>1×Ç
[Try it online!][TIO-jf4fnv1k]
[Jelly]: https://github.com/DennisMitchell/jelly
[TIO-jf4fnv1k]: https://tio.run/##y0rNyan8/18n9FHjnkdNa7we7tqh46qgwOUD5BxuP7zM0c3ncNuhTce6uB7u3nJoa5TPodU@doaHpx9u////fwpXChAZGnOl6OrqAgA "Jelly – Try It Online"
`[0.0, 0.0]`=Mess
`[0.0, 1.5707963267948966]`=Rectangle
`[0.0, 0.7853981633974483]`=Square
`[1.5707963267948966, 0.0]`=Triangle
---
`Ỵ` splits the input on newlines to get a list of lines and `µ` starts a new monadic link with the list of lines as it's argument.
`ZL«L>1` checks whether the input is a single line or if all lines only have 1 character. Returns `0` if it is and `1` if it isn't. `Ç` calls the second link (which calls the third) and at the end if the input is a single line the result of `Ç` gets multiplied by `0` so it doesn't get confused for a rectangle, square or triangle.
In the beginning of the second link: `L€` calculates the length of each line of the input and this list of ints is passed to the third link with `Ç`.
In the third link `,U` pairs the list of line lengths with it's reverse. `⁼€J` checks if `€`ach of these is equal to `[1 2 .. n]` where `n` is the number of lines (what `J` returns). If either of these is true `Ẹ` (any) returns `1` which means we have a triangle and `0` if we don't have one. Finally, `E` checks whether all lines have the same length and this result gets paired with the `0`/`1` indicating triangularness. There are two extra spaces at the end to pad this line to the same length as the other two.
So at the end of the third line we have `[1,0]` if the input is a triangle and `[0,1]` if the input is a rectangle or square. Now back to the second link.
`FLƲ` acts as a monad (`Ɗ` groups them together). It `F`lattens the list of lines, takes the `L`ength then checks if it is a s`Ʋ`quare number. This test isn't perfect however because it yields `1` for an input like
a3.
4
that has a square number of elements but isn't a square.
This is where `æA` (arctan2) comes in. `0æA0` == `0æA1` == `0`. In other words, if the input has square number of elements but is not a rectangle, then it is not a square. There are certainly more clear ways to do this but what does that matter when we have bytes to think about and we are allowed consistent arbitrary output.