# Challenge: Triangles puzzle

Discussion in 'Java' started by Jim Newton, Oct 16, 2004.

1. ### Jim NewtonGuest

Sorry, but i do not agree with your solution.
You missed many triangles.

E.g., P0 -> P8 -> P5 -> P0 is a triangle of zero area.
but it is not counted in th solution of 27.

-jim

Frank Buss wrote:
> I've setup a challenge, mainly for C++, Java and Lisp, but every other
> language is welcome:
>
> http://www.frank-buss.de/challenge/index.html
>
> There is nothing to win, but I hope there will be some interesting
> solutions at the end, so the win are the results
>

Jim Newton, Oct 16, 2004

2. ### Frank BussGuest

Frank Buss, Oct 16, 2004

3. ### Frank BussGuest

Jim Newton <> wrote:

> Sorry, but i do not agree with your solution.
> You missed many triangles.
>
> E.g., P0 -> P8 -> P5 -> P0 is a triangle of zero area.
> but it is not counted in th solution of 27.

you are right, this was not exact enough, I've updated the web page. Only
triangles with area>0 should be counted.

--
Frank Buß,
http://www.frank-buss.de, http://www.it4-systems.de

Frank Buss, Oct 16, 2004
4. ### YogoGuest

> Sorry, but i do not agree with your solution.
> You missed many triangles.
>
> E.g., P0 -> P8 -> P5 -> P0 is a triangle of zero area.
> but it is not counted in th solution of 27.

hmm...

A triangle with an area equal to zero doesn't exist. A triangle has three
angles and none of them may be equal to zero, otherwise you just don't have
a triangle.

What you describe with P0 -> P8 -> P5 -> P0 is a segment of a line not a
triangle...

Yogo, Oct 16, 2004
5. ### SudsyGuest

Frank Buss wrote:
> I've setup a challenge, mainly for C++, Java and Lisp, but every other
> language is welcome:
>
> http://www.frank-buss.de/challenge/index.html
>
> There is nothing to win, but I hope there will be some interesting
> solutions at the end, so the win are the results
>

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.

Sudsy, Oct 16, 2004
6. ### Mikael BrockmanGuest

Frank Buss <> writes:

> I've setup a challenge, mainly for C++, Java and Lisp, but every other
> language is welcome:
>
> http://www.frank-buss.de/challenge/index.html
>
> There is nothing to win, but I hope there will be some interesting
> solutions at the end, so the win are the results

Thanks Frank. Fun way to waste half an hour.

Mikael Brockman, Oct 17, 2004
7. ### Raymond MartineauGuest

On Sat, 16 Oct 2004 23:29:52 +0200, "Yogo" <n o s p a m> wrote:

>> Sorry, but i do not agree with your solution.
>> You missed many triangles.
>>
>> E.g., P0 -> P8 -> P5 -> P0 is a triangle of zero area.
>> but it is not counted in th solution of 27.

>
>hmm...
>
>
>A triangle with an area equal to zero doesn't exist.

Not as far as a computer is concerned. Without any form of sanity
checking, the most intuitive (read: quickest for the programmer to
implement) definition of a triangle for a computer is a set of three
points.

The puzzle in question only considers triangles to be formed from a given
set of points, as well requiring a known line connecting between those
points. Although the puzzle didn't define triangle, the webpage now
includes an update that requires these traingle to have an area.

>A triangle has three
>angles and none of them may be equal to zero, otherwise you just don't have
>a triangle.
>
>What you describe with P0 -> P8 -> P5 -> P0 is a segment of a line not a
>triangle...

Using the "three angles" definition, the line given is valid. There are
three angles in the shape:

P5 -> P0 -> P8 : 0 degree angle
P0 -> P5 -> P8 : 180 degree angle
P0 -> P8 -> P5 : 0 degree angle.

0 degrees is still an angle, as is 180. These angles are generally
significant as they indicate parallel lines, but can be valid in figures.

Raymond Martineau, Oct 17, 2004
8. ### Tayssir John GabbourGuest

Frank Buss <> wrote in message news:<cks0s2\$6a9\$>...
> I've setup a challenge, mainly for C++, Java and Lisp, but every other
> language is welcome:
>
> http://www.frank-buss.de/challenge/index.html
>
> There is nothing to win, but I hope there will be some interesting
> solutions at the end, so the win are the results

Would it be possible for you to have a private mailing list where you
can show us peoples' submissions? I'm too impatient to wait until the
25th. The recipients can be people who already sent you solutions.

It is interesting to see how one programs differently when shipping
time is a factor. After I sent it to you and took a quick look at the
code, I realized I left in parameters named "blah". Which is what I
frequently name things, but I always rename them.

MfG,
Tayssir

Tayssir John Gabbour, Oct 17, 2004
9. ### JeffGuest

Tayssir John Gabbour wrote:

> It is interesting to see how one programs differently when shipping
> time is a factor. After I sent it to you and took a quick look at the
> code, I realized I left in parameters named "blah". Which is what I
> frequently name things, but I always rename them.

How very true. I'm also curious to see if anyone comes up with a
"general case" solution to the problem. I'm in the console gaming
industry, where most of the time hard-coding a solution to a specific
problem is preferable -- which is why I did in this case.

Jeff M.

Jeff, Oct 17, 2004
10. ### Jim NewtonGuest

>
> hmm...
>
> What are you talking about?
>
> A triangle with an area equal to zero doesn't exist. A triangle has three
> angles and none of them may be equal to zero, otherwise you just don't have
> a triangle.
>
> What you describe with P0 -> P8 -> P5 -> P0 is a segment of a line not a
> triangle...
>
>
>

no, you are wrong. an angle may have zero degrees, or less than zero
degrees or more than zero degrees.

the sum of the angles in a triangle is 180 degrees. and a 0, 0, 180
triangle is still a triangle.

Jim Newton, Oct 17, 2004
11. ### Andrew ThompsonGuest

On Sun, 17 Oct 2004 11:02:55 +0200, Jim Newton wrote:

>> A triangle with an area equal to zero doesn't exist. A triangle has three
>> angles and none of them may be equal to zero, otherwise you just don't have
>> a triangle.
>>
>> What you describe with P0 -> P8 -> P5 -> P0 is a segment of a line not a
>> triangle...

>
> no, you are wrong. an angle may have zero degrees, or less than zero
> degrees or more than zero degrees.
>
> the sum of the angles in a triangle is 180 degrees. and a 0, 0, 180
> triangle is still a triangle.

There are a number of properties that a construct must
posess to be considered a triangle. Amongst them are..

a) Internal angles add to 180 degrees.
b) The length of any two sides exceeds the length of the third.
c) Is a 'three sided polygon'

The case in question fits part a), but neither of parts b)
(true in two cases, but not the third), or c) ('two sides'
joined end to end are a single line, thus form a *single*
side, which, when superimposed over the third side becomes
a *line*, people...)

The 'solution' to this is to define the conditions under
which the shapes are acceptable, and to put at the end,
'we will refer to these as triangles, irrespective of the
exact mathematical definition of a triangle'

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Andrew Thompson, Oct 17, 2004
12. ### Jim NewtonGuest

no, the triangle inequality says | a + b | >= a + b
equality is allowed in the triangle inequalilty.

-jim

> You're wrong. The triangle inequality states that the sum of two
> triangles sides exceeds the other side. Zero is not a side in any
> triangle.

Jim Newton, Oct 17, 2004
13. ### Mikael BrockmanGuest

Jim Newton <> writes:

> > hmm...
> > What are you talking about?
> > A triangle with an area equal to zero doesn't exist. A triangle has
> > three angles and none of them may be equal to zero, otherwise you
> > just don't have a triangle.
> > What you describe with P0 -> P8 -> P5 -> P0 is a segment of a line
> > not a triangle...
> >

>
> no, you are wrong. an angle may have zero degrees, or less than zero
> degrees or more than zero degrees.
>
> the sum of the angles in a triangle is 180 degrees. and a 0, 0, 180
> triangle is still a triangle.

You're wrong. The triangle inequality states that the sum of two
triangles sides exceeds the other side. Zero is not a side in any
triangle.

Mikael Brockman, Oct 17, 2004
14. ### Jim NewtonGuest

> There are a number of properties that a construct must
> posess to be considered a triangle. Amongst them are..
>
> a) Internal angles add to 180 degrees.
> b) The length of any two sides exceeds the length of the third.
> c) Is a 'three sided polygon'
>

I do not believe most geometries insist on (b) being the case.
Nothing important is gained by this condition.

a 0/0/180 triangle is a THREE SIDED POLYGON

This sounds like the argument made by the romans when
mathematicians insisited there was a need for a zero
in the number system.

0 is a valid integer
0 miles per hours is a valid speed
0 square meters is a valid area
0 degrees is a valid angle

Jim Newton, Oct 17, 2004
15. ### Frank BussGuest

(Tayssir John Gabbour) wrote:

>
> Would it be possible for you to have a private mailing list where you
> can show us peoples' submissions? I'm too impatient to wait until the
> 25th. The recipients can be people who already sent you solutions.

I've created a private submitters area and I'll send the access information
to every submitter of a working solution.

--
Frank Buß,
http://www.frank-buss.de, http://www.it4-systems.de

Frank Buss, Oct 17, 2004
16. ### Jim NewtonGuest

you're right.. my >= was backward.
sorry.

the triangle inequality is

| a + b | <= | a | + | b |

E.g.,

| -1 + 2 | = 1 <= | -1 | + | 2 | = 1 + 2 = 3
1 <= 3

| 1 + 2 | = 3 <= | 1 | + | 2 | = 1 + 2 = 3
3 <= 3

Andrew Thompson wrote:
> On Sun, 17 Oct 2004 12:37:33 +0200, Jim Newton wrote:
>
> (A.T.)
>
>>>b) The length of any two sides exceeds the length of the third.

>
> ...
>
>>I do not believe most geometries insist on (b) being the case.

>
>
> Less than 7 minutes ago you were claiming to Mikael ..
>
> "no, the triangle inequality says | a + b | >= a + b
> equality is allowed in the triangle inequalilty."
>
> So ..what are your 'beliefs' going to be in another 10 minutes?
>

Jim Newton, Oct 17, 2004
17. ### Andrew ThompsonGuest

On Sun, 17 Oct 2004 12:37:33 +0200, Jim Newton wrote:

(A.T.)
>> b) The length of any two sides exceeds the length of the third.

....
> I do not believe most geometries insist on (b) being the case.

Less than 7 minutes ago you were claiming to Mikael ..

"no, the triangle inequality says | a + b | >= a + b
equality is allowed in the triangle inequalilty."

So ..what are your 'beliefs' going to be in another 10 minutes?

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Andrew Thompson, Oct 17, 2004
18. ### Jim NewtonGuest

why do you think a 0/0/180 triangle is not closed?

-jim

Yogo wrote:
>>a 0/0/180 triangle is a THREE SIDED POLYGON
>>

>
>
> A polygon is a closed figure (each line segment must intersects exactly two
> other line segments). You don't get a closed figure with that.
>
> Besides that, not only the sum of the three angles of a triangle must be
> equal to 180, the sum of two angles must also be less than two right angles.
>
> A line segment is just a line segment.
>
>
>

Jim Newton, Oct 17, 2004
19. ### Jim NewtonGuest

in a 0/0/180 triangle each side intersects its two neighboring
sides.

why do you think that the sum of two angles must also be less
than two right angles?

I think you are trying to put a lot of additional requirements
on the definition of a triangle. You are making it harder than
it is.

Yogo wrote:
>>a 0/0/180 triangle is a THREE SIDED POLYGON
>>

>
>
> A polygon is a closed figure (each line segment must intersects exactly two
> other line segments). You don't get a closed figure with that.
>
> Besides that, not only the sum of the three angles of a triangle must be
> equal to 180, the sum of two angles must also be less than two right angles.
>
> A line segment is just a line segment.
>
>
>

Jim Newton, Oct 17, 2004
20. ### YogoGuest

>
> a 0/0/180 triangle is a THREE SIDED POLYGON
>

A polygon is a closed figure (each line segment must intersects exactly two
other line segments). You don't get a closed figure with that.

Besides that, not only the sum of the three angles of a triangle must be
equal to 180, the sum of two angles must also be less than two right angles.

A line segment is just a line segment.

Yogo, Oct 17, 2004