Hi, here they are:
ProgramA takes a list of integers and finds the rational number whose continued fraction is that list. I have the list stored in L1. I would like to input the list as {n1, n2, ...} but I cannot.
EXPORT ProgramA()
BEGIN
LOCAL M:=[[1,0],[0,1]];
FOR I FROM 1 TO SIZE(L1) DO
M:=M*EXPR("[["+L1(I)+",1],[1,0]]");
END
PRINT(exact(M(1,1)/M(2,1));
END;
ProgramB inputs a rational number P/Q and outputs its continued fraction expansion (and writes it to list L1 also). I have to input the number as P and then Q; if I input P/Q the Prime makes that into a decimal, and the program sometimes does not work. Also, in 5th line, "not0" is for the "slashed equal" sign.
EXPORT ProgramB(P,Q)
BEGIN
LOCAL M,N:={};
M:=EXPR("[[1,0,"+P+"],[0,1,"+Q+"]]");
WHILE M(2,3) not0 DO
N:=CONCAT(N,{FLOOR(M(1,3)/M(2,3))});
M:=EXPR("[[0,1],[1,"+-FLOOR(M(1,3)/M(2,3))+")*M;
END;
L1:=N;
PRINT(N);
END;
(I have just copied these rather that posting pics. There may be some typo.) (BTW, and earlier version would not work with iPart instead of FLOOR).
If I run ProgramB on a number P/Q and then run ProgramA, this one has trouble reading list L1. I have not seen any consistent error to figure out what is wrong. If I run the Debug feature in ProgramA, most of the time works OK, but sometimes it does not, showing that list L1 has some strange items in it, even when L1 looks OK using [Shift]+[7]
Thanks!
[added] In programB, third line from the bottom, I have N->L1; instead of L1:=N. I just do not have that "store" symbol on my keyboard)
[/added]
Edited: 3 Dec 2013, 2:44 p.m. after one or more responses were posted