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 Answer

replaced http://math.stackexchange.com/ with https://math.stackexchange.com/
Source Link
  • OP said "all input numbers are well-formed with respect to the datatypes you end up using"
  • Golfscript does not have floating point numbers - not inherently anyway
  • It's impossible (in a 2-dimensional grid) to have an equilateral triangle with integer coordinates, as proven here here.
  • OP said "all input numbers are well-formed with respect to the datatypes you end up using"
  • Golfscript does not have floating point numbers - not inherently anyway
  • It's impossible (in a 2-dimensional grid) to have an equilateral triangle with integer coordinates, as proven here.
  • OP said "all input numbers are well-formed with respect to the datatypes you end up using"
  • Golfscript does not have floating point numbers - not inherently anyway
  • It's impossible (in a 2-dimensional grid) to have an equilateral triangle with integer coordinates, as proven here.
Source Link
A Frayed Knot
  • 3.6k
  • 3
  • 18
  • 18

Golfscript (175 bytes)

~..|,({.)2$([\;\]@(;]{{~}/@- 2?@@- 2?+}%$.{2-1??100*}/-+abs 1<{;"Line"}{.[]|,((["Isosceles ""Scalene "]=\~-+.!["Oblique ""Right "]=\.!0円>-)["Acute ""Obtuse "]=}if}{;"Point "}if

You can test it here (test set included).

Input format:

"[x y][x y][x y]"

Commented version:

~ # evaluates input string 
..|,( # pushes the number of unique coords - 1
{
 .)2$([\;\]@(;] # makes all 3 possible pairings of coords
 {{~}/@- 2?@@- 2?+}%$ # gets all squares of side lengths 
 .{2-1??100*}/-+abs 1< # 0 if triangle, 1 if line
 {;"Line"}
 {
 .[]|,((["Isosceles ""Scalene "]=\ # removes duplicate side-squares,
 # and use the count to determine
 # if isosceles or scalene (no
 # equilaterals will exist)
 ~-+.!["Oblique ""Right "]=\ # compute a^2 + b^2 - c^2. Use to
 # determine if oblique or right.
 # c = max side length 
 .!0円>-)["Acute ""Obtuse "]= # use same value to determine if
 # acute, obtuse, or right
 }
 if
}
{;"Point "}
if

NOTE:

The reason my code contains no "equilateral" output is because:

  • OP said "all input numbers are well-formed with respect to the datatypes you end up using"
  • Golfscript does not have floating point numbers - not inherently anyway
  • It's impossible (in a 2-dimensional grid) to have an equilateral triangle with integer coordinates, as proven here.

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