Programming Challenge!
|
02-19-2017, 10:35 PM
(This post was last modified: 02-19-2017 11:00 PM by toml_12953.)
Post: #1
|
|||
|
|||
Programming Challenge!
My job was to convert old-style BASIC programs to the Prime's HPPL.
Below is an example from Problems for Computer Solution by Stephen J. Rogowski. It is a classic example of spaghetti code that I converted to work on the Prime. Just so you don't think I'm trying to get someone here to do my work for me, I will post another message with my solution. If you want to do the mental exercise, don't look at the solution post before trying the conversion yourself! That would spoil the fun! Tom L Code: 10 DIM X(126),K(2) Tom L Cui bono? |
|||
02-19-2017, 10:40 PM
(This post was last modified: 02-19-2017 10:57 PM by toml_12953.)
Post: #2
|
|||
|
|||
RE: Programming Challenge! A Solution
Here's a solution to the problem that tries to keep as close to the original as possible. It uses the same variable names and techniques as the original. If you run the original in BASIC and the below HPPL program, you'll see that they give the same answers. I hope you had fun!
Tom L Code: FNA(X,Y,Z) Here's the TAB Function: Code: EXPORT TAB(X) Tom L Cui bono? |
|||
02-20-2017, 04:39 PM
Post: #3
|
|||
|
|||
RE: Programming Challenge!
After a quick glance at the BASIC code, I wondered if you may be better off looping on L from 1 to 125 (or 126?) and then calculating T to be T:=T+0.2; or T:=L/5. This avoids having to round off with IP().
Graph 3D | QPI | SolveSys |
|||
02-20-2017, 10:52 PM
(This post was last modified: 02-20-2017 10:55 PM by toml_12953.)
Post: #4
|
|||
|
|||
RE: Programming Challenge!
(02-20-2017 04:39 PM)Han Wrote: After a quick glance at the BASIC code, I wondered if you may be better off looping on L from 1 to 125 (or 126?) and then calculating T to be T:=T+0.2; or T:=L/5. This avoids having to round off with IP(). That's true but since I was trying to stay as close as possible to the original, I opted to keep the same looping. I also wrote a much better version that uses an algebraic technique rather than this iterative solution. It's much shorter and more accurate but I didn't use it for the same reason as above. Code: FNH(V,T) Tom L Tom L Cui bono? |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)