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

Return to Revisions

5 of 5
added 298 characters in body
dylnan
  • 5.4k
  • 2
  • 17
  • 34

Jelly, (削除) 32 (削除ここまで) 27 bytes

,U=€JẸ,E;SÆ2$
ZL«L’aL€Ç$æAƝ

Try it online!

Now taking input at a list of lines and switched &g×ばつ with ’a and using SÆ2 after L€ instead of FLÆ2Ɗ. These allowed me to condense into two lines and I saved 5 bytes in total. The following values are the same as before.

[0.0, 0.0]=Mess
[0.0, 1.5707963267948966]=Rectangle
[0.0, 0.7853981633974483]=Square
[1.5707963267948966, 0.0]=Triangle


ZL«L gets the minimum of height and width and subtracts 1 from it. Ç calls the second link and at the end if the input is a single line the result of Ç gets logical ANDed with the previous number if there is only a single line the output will be [0.0, 0.0].

In the second link: ,U yields a list of line lengths paired with it's reverse. J is range(number of lines) and =€ checks whether each of them are equal to the result of J. (Any) yields 1 if the input is a triangle.

E checks if all line lengths are equal (rectangle/square).

SÆ2 with a $ to group them into a single monad checks whether the total number of characters is a square number.

So at the end of the second link we have [[a,b],c] where each number is 0 or 1 indicating whether the input is a triangle, rectangular, and has square number of characters respectively.

However a square number of elements doesn't imply the input is a square since an messy input like

a3.
4

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.

Note I was previously using æA/ instead of æAƝ (and a , instead of a ; in the second link) but the former method distinguishes between triangles that have square number of elements and those that don't but they should obviously be counted as the same thing.

dylnan
  • 5.4k
  • 2
  • 17
  • 34

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