Subj : Re: Dartmouth BASIC to C To : comp.programming From : jimmaureenrogers@worldnet.att.net Date : Mon Aug 08 2005 05:06 pm Jon Harrop wrote: > John Smith wrote: > > > Having nothing better to do on a Saturday morning, I was looking at > > Kemeny & Kurtz's 1964 manual for BASIC: > > > > http://www.bitsavers.org/pdf/dartmouth/BASIC_Oct64.pdf > > > > Below is a C port of the first example program given in the manual. Can > > it be improved while preserving, as much as possible, the structure of > > the original BASIC program? > > I've no idea, but here's an OCaml port, just for fun: And here is an Ada port, just for fun: ----------------------------------------------------------------------- -- An Ada port of the 1st program given in Kemeny & Kurtz's -- manual for 1964 Dartmouth BASIC. It solves a system of -- linear equations with three different right sides. -- (A1*X1) + (A2*X2) = B1 -- (A3*X1) + (A4*X2) = B2 ----------------------------------------------------------------------- with Ada.Text_Io; use Ada.Text_Io; procedure Linear is type Pairs is array(1..2) of Float; type Pair_List is array(1..3) of Pairs; Data : constant Pair_List := ((-7.0, 5.0), (1.0, 3.0), (4.0, -7.0)); A1, A2, A3, A4 : Float; D : Float; X1, X2, B1, B2 : Float; begin A1 := 1.0; A2 := 2.0; A3 := 4.0; A4 := 2.0; D := A1 * A4 - A3 * A2; if D = 0.0 then Put_Line("NO UNIQUE SOLUTION"); else for I in Data'range loop B1 := Data(I)(1); B2 := Data(I)(2); X1 := (B1 * A4 - B2 * A2) / D; X2 := (A1 * B2 - A3 * B1) / D; Put_Line(Float'Image(X1) & " " & Float'Image(X2)); end loop; end if; end Linear; I notice that the formulas in the comment differ from the formulae in the code (comments have a "+" while the code has a "-"). Jim Rogers .