Ti-84 +CE If-Then-else Syntax error - if-statement

EDIT: Full code has been included, because it seems possible that the error may lie in the Else or End commands that are also part of the If-Then conditional.
Programming newbie here. I did see the many other if-else syntax error questions but seeing them, was worried that they did not address exactly whatever problem is going on in my case.
I have the following lines of commands on a TI-84 program I'm making.
This is part of a program I made that solves for the other sides/angles of a triangle given some other sides/angles.
Below are the lines of programming I included for the ambiguous case (SSA triangle), which happens if the supplement of the angle B solved for (given Side A, Angle A, and Side B) is less than 180 when added to the given Angle A. In this case, there are two different triangle cases-- one with angle B as the initially solved angle B, and the other with angle B being equal to the supplement of the 1st case's angle B.
Otherwise, if this condition is not satisfied (the supplement + Angle A is greater or equal to 180), then only one triangle exists.
Lbl 0 is just a label these lines of programming go to after all triangle values are calculated. It then calculates certain other values of this triangle based off of all of the angles & sides.
Lbl 2
Disp "Side A, Side B, Angle A"
Pause
Prompt A,B,D
sin(B*sin(D)/A)→E
If ((180-E+D)<180)
Then
Disp "Case 1"
Pause
180-D-E→F
A*sin(F)/sin(D)→C
Disp "Angle B=",E
Disp "Angle C=",F
Disp "Side C=",C
(A+B+C)/2→S
√(S(S-A)(S-B)(S-C))→H
Disp "Area=",H
Pause
Disp "Case 2"
Pause
180-E→E
180-D-E→F
A*sin(F)/sin(D)→C
(A+B+C)/2→S
√(S(S-A)(S-B)(S-C))→H
Disp "Angle B=",E
Disp "Angle C=",F
Disp "Side C=",C
Pause
Disp "Area=",H
Goto 0
Else
180-D-E→F
A*sin(F)/sin(D)→C
Disp "Angle B=",E
Disp "Angle C=",F
Disp "Side C=",C
Pause
Goto 0
End
The square is just an inverse (^-1) sign. It formats correctly in the TI Connect CE software that I'm using.
I assumed that the If-then lines were the problem lines, because removing them removes the SYNTAX error. Another possibility is that I set up my Else And End incorrectly, though I did consult the TI-Basic Developer Wiki and my setup seemed to be right.
What is wrong with the syntax of the If-then lines that is causing this error?

I did not see any problems when I tried this on my calculator. The only thing that I thought could have been an error was the parenthesis around the if argument...
If ((180-E+D)<180)
vs
If 180-E+D<180
The program worked for me, so I can't identify a problem...
If you get the error and choose Goto, what line of the code does the calculator say the error is on?

Related

How to create an elbow connector from scratch programatically?

An "elbow connector" in MS-Word is a 3-segment line with a control point in the middle as shown
where if I move the yellow control point sideways, then the length of the two lines on either side change accordingly while the end points remain the same. (Please ignore the "2" in the picture)
I am trying to understand how this works so that I can re-create this. Is there a "line equation" for such a line? I have some points (x,y) that are already in the shape of this elbow connector but I would like to incorporate the functionality of changing the lines on either side by controlling the control point. How would I go about re-creating this?
By dissecting the lines like:
For moving the center(M) only sideways, length of lines 2 and 3 remains the same so the problem becomes how to calculate length (and direction) of the lines 1 and 4.
That can be calculated like:
line1_length = B.x - M.x;
line4_length = M.x - A.x;
For directions a comparison should first be made like:
if(B.x > M.x)...
.
.
.
if(M.x > A.x)...
.
.
.
Beginning points is already known as the position of A and the position of B. By knowing the lengths and directions of lines 1 and 4, the end points can be determined.
Good luck!

Given a matrix of N*M , find the minimum no. steps in worst case to reach to particular cell?

One can enter the matrix from any cell, and each cell contains some clue regarding the position of the cell needed to be found like
Total 8 types of clues can be present:
Exactly Above it
Exactly Below it
Exactly To the Right
Exactly To the Left
In the Top Right Region
In the Bottom Right Region
In the Top Left Region
In the Bottom Left Region
In each step he can move to one adjacent cell as per the above eight movements.
My question is minimum no. of steps he needs to take to reach that cell in the worst case.
Test Case :
2 2 : 1
3 3 : 1
My solution looked like this :
I thought If I start from the middle region of the matrix , then I would have to take the minimum no. of steps.
cin >> n >> m ;
ans = max ( n/2 , m/2 ) ;
But obviously it was wrong.
The correct solution looked like this
cin >> n >> m ;
ans = log( max(n,m) , 2) ; //base 2
Can anyone explain this ?
The question can be found here : http://www.codechef.com/TRNT2014/problems/TR001
These two items:
In each step he can move to one adjacent cell as per the above eight movements.
The correct solution looked like this:
ans = log( max(n,m) , 2) ; //base 2
are in contradiction. If the first is true, then your solution is correct. If the second is true, then the first must be false, and he can jump to any cell (or at least a cell (n/4,m/4) away).
Contrary to the description above, the linked description does not seem to limit which box you can check at any time.
As such, the correct approach seems to be basically a 2D binary search. Start at the middle box. If (for example) the clue says the correct box is up and to the right, move half the distance toward that corner. At that point, it might say (for example) that the correct box is up and to the left. If so, you move half the distance that direction.
In short, it's a binary search, except that the result at each point is a vector--a direction and a distance--rather than just a distance as you'd have in a typical 1D binary search.

C++ alternative algorithm for solution

I need some help with an algorithm, I have a problem with an program.
I need to make a program where user inputs cordinates for 3 points and coefficient
for linear funciton that crosses the triangle made by those 3 points and i need to compare area of the shapes what is made function crossing that triangle.
I would paste code here but there is things in my native language and i just want to know your alogrithms for this solution, becuase my wokrs only if the points are entered in exact sequence and I cant get handle of that
http://pastebin.com/vNzGuqX4 - code
and for example i use this http://goo.gl/j18Ch0
The code is not finnished, I just noticed if I enter it in different sequence it does not work like when entering points " 1 1 2 5 4 4 0.5 1 5 " works but " 4 4 1 1 2 5 0.5 1 5 " does not
The linear must cross with 2 edges of the triangle at least. So you can find these 2 crossing points first, these 2 points with one of the 3 vertices will make a small triangle. Use this equation to calculate the area of a triangle S = sqrt(l * (l-a) * (l-b) * (l-c)) where l = (a+b+c)/2 and a, b, c are the length of the edge. It should be easy to get the length of an edge given the coordinate of the vertex. One is the area of the small triangle, the other one is the area of the big triangle minus the small one.
If your triangle is ABC, a good approach would be the following:
Find lines that go through points A and B, B and C, and C and A.
Find the intersection of your line with these three lines.
Check which two intersections lie on the triangle sides.
Depending on the intersections calculate the surface of the new small
triangle.

how to avoid overlaps during midpoint displacement? (2D)

hell-o guys!
well, I'm playing with random walks. Midpoint displacement gives some nice results, but I would like a random walk without walk loops, like the ones (in yellow) on this screen-hot :
My first idea to deal with that problem is to check for each segment if there is an intersection with all others segments, then to delete the walk loop between the both segments and bind at the interesection point. But for some walks, it would give a strange result, like that one :
where the yellow part is a loop, and we can see that a big part of the walk would be deleted if I do what I said.
Maybe another method would be to check, when the displacement of the midpoint is made, if the segments are interesecting. In case of there is an intersection, get another displacment. But it looks to become very time consuming quickly when the number of subdivisions rises...
So I would like to know if there is a way to avoid these loops
so... it's seems playing with the amplitudes of the random numbers is a good way to avoid overlaps :
the path without displacement is drawn in cyan. I didn't get overlaps with these displacments :
do{
dx = (D>0)? 0.5*sqrt((double)(rand()%D)) - sqrt((double)D)/2. : 0 ;
dz = (D>0)? 0.5*sqrt((double)(rand()%D)) - sqrt((double)D)/2. : 0 ;
}while(dx*dx+dz*dz>D);
where D is the squared distance between the two neibourers of the point we want to displace. The (D>0)? is needed to avoid some Floating Point Exception.

BFS algorithm - shortest walk on grid with constrained steps

The problem is as follows: A wanderer begins on the grid coordinates (x,y) and wants to reach the coordinates (0,0). From every gridpoint, the wanderer can go 8 steps north OR 3 steps south OR 5 steps east OR 6 steps west (8N/3S/5E/6W).
How can I find the shortest route from (X,Y) to (0,0) using breadth-first search?
Clarifications:
Unlimited grid
Negative coordinates are allowed
A queue (linked list or array) must be used
No obstacles present
The algorithm for this problem would be:
For each axis, step towards it until your position on the other axis is 0.
Pseudocode:
while (x!=0) {
if (x>0) x-=6;
else x+=5;
}
while (y!=0) {
if (y>0) y-=8;
else y+=3;
}
However, I don't understand why you need to search for a route - it's not that complicated.
As "thejh" remarked there's no need for a search, but your assignment calls for one.
A reasonable approach is
Analyze. Is it all possible for arbitrary (x, y) starting position? Checking the allowed moves you see that they can be combined to yield 1-step horizontal moves, and 1-step vertical moves, so the answer to that is yes (for your hand-in provide the details of this).
Figure out what "breadth-first search" is. Wikipedia is your friend (although, if you have access to a university library, I really do recommend Patrick Henry Winston's old Artifical Intelligence, it's really good, very lucid explanations). Try it out with some simpler problem.
Do the assignment's problem in just about the same way. Ask here if you encounter any technical C++ problem.
Cheers & hth.,
Here's my answer (really based off of thejh's answer) that uses a queue:
//set x to start position
//set y to start position
do {
if (x<0) Queue.Push(8N);
if (x>0) Queue.Push(3S);
if (y<0) Queue.Push(5E);
if (y>0) Queue.Push(6W);
while (!Queue.Empty())
{
Move(Queue.Pop());
}
} while (x && y);
It's convoluted, but follows the directions.
I'm going to go ahead and answer my own question for future reference.
Psuedocode:
while (true) {
if (destination reached)
break;
addToQueue(go north);
addToQueue(go south);
addToQueue(go east);
addToQueue(go west);
getNextFromQueue;
}
It should also be noted that the execution time for this application grows very, very fast, so test it out with small coordinate values. For example, the coordinates (1,1) gives 7 levels of breadth and requires 16384 iterations.