NeverSayNever's blog

By NeverSayNever, 9 years ago, In English

Hello all,

I am trying to solve this problem .

1
                           2   3
                         4   5   6
                       7    8   9  10 
                     11  12  13  14  15... and on so

Given three points A,B,C such that A <= B <= C. We have to report whether given points form an equilateral triangle or not .

I made this solution and but this is not considering all the cases. Here is my solution .

SOLUTION:

we know that a triangle ABC is equilateral if A==B && B==C. (equality is an equivalence relation).

  1. So Let us consider A,B,C such that A < B < C . Now we can find the side BC as C-B+1.

  2. Next step is to check whether the other two sides are equal to this or not .for that purpose .. we can calculate the level of each of A,B and C then take the difference.. for any nodes its level will be x A<=(x*(x+1))/2 for the smallest possible x.

comparing all the three to check the existence of an equilateral triangle .

Here is the python implementation link of the above idea http://ideone.com/V5fuhe

but this will fail on the test case 5 , 13 , 15 answer should be false but my code will report is true .

Can anyone suggest me some idea to solve this problem ..

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Also you need to check that the distances from start of the corresponding lines to numbers A and B are equal. If number A lies on level x, the distance is equal to A - x * (x - 1) / 2

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you so much You mean i need to compare the distance from start of line to the first number and to the second number. These both result should be equal.

»
9 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

My personal doubleposting problems :\

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I would solve like this:

Let's find levels of our numbers: LA, LB, LC.

Cases:
1) LA ≠ LB ≠ LC
2) LA = LB = LC
3) LA = LB
4) LB = LC
In first two cases answer is false.
Last two cases are equal so let's consider that we have case №3.

If B - A ≠ LC - LA then answer is false.
Otherwise let's count first elements in rows LA and LC: FA, FC.
And now if C - FC = B - FA then answer is true, otherwise false.

So for case №2 answer will be C — B == LC - LA && A — FA == B — FC.

So the total answer is C — B == LC - LA && B — A == FC - FA || B — A == LC - LA && C — B == FC - FA.

Strange formulas came from looking at this triangle thing.