▼
Posts: 320
Threads: 59
Joined: Dec 2006
Something to keep your mind occupied whilst waiting for your 35s.
This may be an old problem for some, but still a nice challenge.
Three panes of glass are arranged parallel to each other. Each pane allows 70% light through, reflects 20%, and absorbs 10%. What percentage of light will pass entirely through all panes of glass? Assume a beam of light is emitted to the left of the three panes and exits to the far right; how much emits out to the right? Careful.
▼
Posts: 8
Threads: 2
Joined: Jul 2007
I admit I am being picky here, but can we assume the following while answering this question:
1) The beam of light is exactly perpendicular to the long axis of the panes of glass (really weak ND filters?)
2) That the beam of light is nonmonochromatic?
3) That the beam of light is not polarized and that the "filters" are not polarizing the light passing through them?
I deal with these types of questions in microscopy all of the time, so I am a bit sensitive to the particulars, I guess ;)
▼
Posts: 320
Threads: 59
Joined: Dec 2006
Don't overanalyze the problem. It's intended to be a "simple" math exercise, not a twisted opticalmicroscopy head basher. Assume the percentage of light transmission, reflection, and absorption is the same in all directions regardless of frequency, polarization, etc.
Also, after a solution is devised, can it be evaluated on an HP calculator. (I did mine with Mathematica.)
▼
Posts: 6
Threads: 0
Joined: Jun 2006
I managed to work out a solution with a 50g. It would have taken me longer to look up the correct functions in Mathematica.
▼
Posts: 320
Threads: 59
Joined: Dec 2006
I haven't yet tried it in my 50g yet. I'll attempt it today to see if it (or I) can manage it.
Posts: 275
Threads: 38
Joined: Jul 2007
Quote:
Don't overanalyze the problem. It's intended to be a "simple" math exercise
Well, if we're not supposed to overanalyse then the answer is a bit more than 70% of 70% of 70%. :)
▼
Posts: 320
Threads: 59
Joined: Dec 2006
Quote:
Well, if we're not supposed to overanalyse then the answer is a bit more than 70% of 70% of 70%. :)
Okay, okay. You can analyze the "bit more" as much as possible. :) That does give you a lowerbound estimate though.
Posts: 562
Threads: 27
Joined: Oct 2006
Quote:
Don't overanalyze the problem. It's intended to be a "simple" math exercise
I was already hoping to use some of these lessons to work on it. GRIN!! (Actually a pretty good collection, and the only online recording I have ever seen of the good Dr.)
Edited: 22 July 2007, 4:08 p.m.
Posts: 111
Threads: 22
Joined: Jul 2007
Ok, so it looks like a limit problem, where 0.7L passes through the first pane (p1), and then there is an infinitely decaying portion that is reflected between p1 and p2, and similarly between p2 and p3. I'm headed out to breakfast w/ my sweet wife (who is tapping her foot while standing at the door)...so at least I have some fun napkinmath at the table :)
I suspect that I can devise a series that will converge on the sum percentage (x) of incident light that may pass through: x*L
ECL
▼
Posts: 320
Threads: 59
Joined: Dec 2006
There's also light that will exit to the left and be lost. The light is zigzagging back and forth infinitely; some is absorbed, some exits to the right, some exits all the way back to the left and is lost. That's what makes it a great problem.
Without giving too much away, my solution involves a couple of summations, a combination, and a limit. Crazy. But I'm very interested in other solutions. We'll have to request answers in a few days.
"Napkinmath". That's great. Many times my wife has caught me doing that during dinner. :)
Posts: 562
Threads: 27
Joined: Oct 2006
Quote:
...my sweet wife (who is tapping her foot while standing at the door...
I myself have made many posts here under the EXACT circumstances!!
Posts: 9
Threads: 3
Joined: Jun 2007
This is a straightforward problem in linear algebra.
Draw a picture, work from the far right and set up the equations using the transmitted light and relected light from every pane. You'll end up with six equations with six unknowns. Using the equation solver for matrices in my HP49g+ I found that the light transmitted out of the third pane is 38.03% of the original light.
I'll email the solution if anyone likes.
▼
Posts: 320
Threads: 59
Joined: Dec 2006
Very nice Hans. I tried a matrix solution on my first attempt, but must have had something out of place. I went with the brute force method. Email me your solution, I'd like to see various methods. Hopefully we'll get a few more.
CHUCK
▼
Posts: 362
Threads: 30
Joined: Jul 2005
I tried the matrix approach as well and found a result for transmission a bit higher. I also got just above 30% reflected
Arnaud
Posts: 1,477
Threads: 71
Joined: Jan 2005
5 equations suffice I think:
Picture the 3 panes of glass arranged left to right with the light source on the left.
let:
A = light transmitted from 1st pane to 2nd pane (left to right)
B = light transmitted from 2nd pane to 3rd pane (left to right)
C = light transmitted from 3rd pane on (left to right)
(this is what we want to solve for)
X = light transmitted from 2nd pane back to 1st pane (right to left)
Y = light transmitted from 3rd pane back to 2nd pane (right to left)
Then:
A = .7 + .2X
B = .7A + .2Y
C = .7B
X = .2A + .7Y
Y = .2B
It's pretty simple to solve these exactly:
A = .672/.902
B = .7/.96 * A
C = .7 * B
C = 38.0266075388%
Edited: 23 July 2007, 5:50 a.m.
▼
Posts: 362
Threads: 30
Joined: Jul 2005
What about light reflected back towards the source by the second panel and back again in the right direction by the first panel?
I believe the matrix approach takes care of this one.
Arnaud
Posts: 9
Threads: 3
Joined: Jun 2007
Five equations are all you really need. I set up one additional for the light reflected back towards the source. It's really not needed for the solution but it allows you to get all the light paths.
Hans
Posts: 320
Threads: 59
Joined: Dec 2006
Katie. This is wonderful. It's VERY close to what I had originally, but had a Z (in your notation) for the light lost to the left, which gives a 6th equation (albeit unecessary). When I solved it with a matrix I must have missed one of those darn negative signs.
CHUCK
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Chuck:
Chuck posted:
"Something to keep your mind occupied whilst waiting for your 35s"
It's been a fair number of days since I got an HP35S but I'll take your interesting challenge anyway.
"Three panes of glass are arranged parallel to each other. Each pane allows 70% light through, reflects 20%, and absorbs 10%. What
percentage of light will pass entirely through all panes of glass? Assume a beam of light is emitted to the left of the three panes and exits to
the far right; how much emits out to the right?" [...] Also, after a solution is devised, can it be evaluated on an HP calculator [?]"
The symbolic solution for arbitrary parameters is pretty trivial from a purely mathematical point of view and writing a program to numerically evaluate it holds
no difficulty either, just a little drudgery, so for a change and as this kind of 'physical/engineering' problem is ideally suited to simulation, here's a novel
Monte Carlo approach which can be concocted in a very few lines, requires no mathematical knowledge whatsoever, can be adapted to run on the simplest calc models without requiring solvers or matrix operations, and delivers a fair approximation
to the exact theoretical result.
The program simulates 10, 100, 1000, ..., 1000000 photons entering through the left side of the leftmost panel, one at a time, simulates their random
interactions with each side of each panel, and duly counts how many of them do exit to the far right. The logic is crystalclear ('P1L' stands for 'Panel 1,
Left side', 'P1R' stands for 'Panel 1, Right side', and so on):
10 DESTROY ALL @ FOR D=1 TO 6 @ C=0 @ FOR N=0 TO 10^D1
20 'P1L': R=RND @ IF R<.7 THEN 'P2L' ELSE 'NXT'
30 'P1R': R=RND @ IF R>.2 THEN 'NXT'
40 'P2L': R=RND @ IF R<.7 THEN 'P3L' ELSE IF R<.9 THEN 'P1R' ELSE 'NXT'
50 'P2R': R=RND @ IF R<.7 THEN 'P1R' ELSE IF R>.9 THEN 'NXT'
60 'P3L': R=RND @ IF R<.7 THEN C=C+1 ELSE IF R<.9 THEN 'P2R'
70 'NXT': NEXT N @ DISP USING "2(7D),5D.2D,A";N,C,C/N*100,"%" @ NEXT D
A sample (repeatable) RUN would be:
>RANDOMIZE PI @ RUN
# Photons Transmit %

10 5 50.00%
100 30 30.00%
1000 367 36.70%
10000 3755 37.55%
100000 38068 38.07%
1000000 380338 38.03%
so it seems that some 38.03% of the photons are transmitted, which agrees with the theoretical result to all four given digits.
The simulation can be easily adapted to coefficients other than 70%20%10% by changing the inline constants, and can also count the number of
photons emerging at the left instead by inserting an incrementing counter at the proper place in the code.
The same approach will also work for any number of panels and for unequal panels (different coefficients for each panel and/or different coefficients for
each side of a panel) by simply changing their inline constants. Thus, it's quite general in nature and, for a reallife engineering problem, would give decent, useable
results with very little intellectual effort even in circumstances where the underlying math necessary for a theoretically exact result would quickly get tremendously
complex or even possibly out of hand.
Best regards from V.
▼
Posts: 320
Threads: 59
Joined: Dec 2006
Valentin, you never cease to amaze me with your prowess. Unfortunately I have two more days to go until my 35s arrives [skrimped on postage :( ], but I may need those two days to decipher your method (excuse my programming naivity, but what is the language?)
"...requires no mathematical knowledge whatsoever..." hmmm?
Valentin
Reminds me of:
"Everything should be made as simple as possible, but not simpler."
Einstein
Edited: 23 July 2007, 10:22 a.m.
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Chuck:
Chuck wrote:
"Valentin, you never cease to amaze me with your prowess."
Thanks, very kind of you.
"Unfortunately I have two more days to go until my 35s arrives [skrimped on postage :( ],
but I may need those two days to decipher your method (excuse my programming naivity, but what is the language?)"
As most of my posted productions, the program is written in HP71B's native BASIC dialect, using plainvanilla statements (no ROMs, etc), as it achieves the perfect balance between power (very short programs) and clarity, so that most people will be able to understand the underlying algorithms and port them to whatever other languages they might prefer (RPN, RPL, ...) with ease.
Thanks a lot for your very interesting challenge, keep them coming :)
Best regards from V.
▼
Posts: 376
Threads: 35
Joined: Jul 2007
How would you do problem on 35s?
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Vincze:
Vincze posted:
"How would you do problem on 35s?"
This is a trivial, onthefly straightforward conversion of my original HP71B BASIC program:
LBL S
STO M RCL V 100
STO N X<Y? RCLx C
0 GTO F002 RCL/ M
STO C GTO B002 FIX 2
0.7 LBL D RTN
STO U RCL U
0.9 RANDOM
STO V X<Y?
0.2 GTO B002
STO W RCL V
LBL A X<Y?
RCL U GTO F002
RANDOM LBL E
X<Y? RCL U
GTO C002 RANDOM
GTO F002 X>Y?
LBL B GTO E009
RCL W 1
RANDOM STO+ C
X>Y? GTO F002
GTO F002 RCL V
LBL C X>Y?
RCL U GTO D002
RANDOM LBL F
X<Y? DSE N
GTO E002 GTO A002
where "/" stands for the division key. Some sample runs:
Pi, SEED
10, XEQ S [ENTER] > 50.00 (%)
100, XEQ S [ENTER] > 30.00 (%)
1000, XEQ S [ENTER] > 36.70 (%)
10000, XEQ S [ENTER] > 37.55 (%)
You might want to optimize it by removing all labels except for the first one (LBL S), but in any case it runs much too slow in the HP35s to be of any use other than as a didactic example of a Monte Carlo simulation.
Notice that the results are exactly the same as the ones given by my original HP71B BASIC program, which strongly suggests both machines are using the exact same pseudorandomnumber generator.
Thanks for your interest and
Best regards from V.
Posts: 1,619
Threads: 147
Joined: May 2006
Quote:
Three panes of glass are arranged parallel to each other. Each pane allows 70% light through, reflects 20%, and absorbs 10%. What percentage of light will pass entirely through all panes of glass? Assume a beam of light is emitted to the left of the three panes and exits to the far right; how much emits out to the right? Careful.
Hello Chuck,
Since others already provided a solution for three panes, I worked on two N panes solutions. The first is calculated (quick, but needs RAM) and the other is simulated (low RAM, but needs time).
Calculated solution:
The following 71B program builds a 2*N1 order sparse matrix to find the exact answer for any N (as long as you have enough RAM). The code should be easy to port to any other HP model with matrix support (sorry no 35S).
10 STD @ DESTROY ALL @ OPTION BASE 1
20 T=.7 @ R=.2
30 M=INT(SQR(MEM/2/8)) @ M=INT((M+1)/2)1
40 INPUT "MAX N=",STR$(M);N0
50 FOR N=1 TO N0
60 DESTROY A,B,X
70 M=2*N1
80 M0=MEM @ REAL A(M,M),B(M,1),X(M,1) @ M1=MEM
90 FOR I=1 TO M @ A(I,I)=1 @ NEXT I
100 FOR I=N+1 TO M @ A(IN,I)=R @ A(I,IN)=R @ NEXT I
110 FOR I=1 TO N1 @ A(I+1,I)=T @ NEXT I
120 FOR I=N+1 TO M1 @ A(I,I+1)=T @ NEXT I
130 B(1,1)=T
140 MAT X=SYS(A,B)
150 IMAGE "P(",2D,")= ",2D.10D,"% ",6D," ppm using",6D," bytes"
160 DISP USING 150;N,X(N,1)*100,X(N,1)*1000000,M0M1
170 NEXT N
180 DESTROY ALL
Lines 1040 setup the environment and prompts for the MAX N to calculate. The 71B, 48/49/50 matrix solver requires 2x the RAM used by the matrix. I assume that this is to preserve the original matrix. My 71B has ~64K free, so I am limited to ~32K for my matrix, or N=32.
Lines 90120 setup the matrix, 140 solves.
Output:
P( 1)= 70.0000000000% 700000 ppm using 62 bytes
P( 2)= 51.0416666667% 510417 ppm using 148 bytes
P( 3)= 38.0266075388% 380266 ppm using 308 bytes
P( 4)= 28.6686567164% 286687 ppm using 532 bytes
P( 5)= 21.7595919186% 217596 ppm using 820 bytes
P( 6)= 16.5796748933% 165797 ppm using 1172 bytes
P( 7)= 12.6612595201% 126613 ppm using 1588 bytes
P( 8)= 9.6815861690% 96816 ppm using 2068 bytes
P( 9)= 7.4088116685% 74088 ppm using 2612 bytes
P(10)= 5.6721177756% 56721 ppm using 3220 bytes
P(11)= 4.3436617759% 43437 ppm using 3892 bytes
P(12)= 3.3268533494% 33269 ppm using 4628 bytes
P(13)= 2.5482999981% 25483 ppm using 5428 bytes
P(14)= 1.9520479145% 19520 ppm using 6292 bytes
P(15)= 1.4953536068% 14954 ppm using 7220 bytes
P(16)= 1.1455268133% 11455 ppm using 8212 bytes
P(17)= .8775487825% 8775 ppm using 9268 bytes
P(18)= .6722642349% 6723 ppm using 10388 bytes
P(19)= .5150036989% 5150 ppm using 11572 bytes
P(20)= .3945314511% 3945 ppm using 12820 bytes
P(21)= .3022410597% 3022 ppm using 14132 bytes
P(22)= .2315397822% 2315 ppm using 15508 bytes
P(23)= .1773772706% 1774 ppm using 16948 bytes
P(24)= .1358846583% 1359 ppm using 18452 bytes
P(25)= .1040981355% 1041 ppm using 20020 bytes
P(26)= .0797472129% 797 ppm using 21652 bytes
P(27)= .0610925284% 611 ppm using 23348 bytes
P(28)= .0468015997% 468 ppm using 25108 bytes
P(29)= .0358536442% 359 ppm using 26932 bytes
P(30)= .0274666640% 275 ppm using 28820 bytes
P(31)= .0210415888% 210 ppm using 30772 bytes
P(32)= .0161194843% 161 ppm using 32788 bytes
The first numeric column is the number of panes, the 2nd is the percentage of photons expected to make it through, the 3rd is the number of photons/million expected to complete the journey, and the 4th is the amount of RAM required for the matrix.
Simulated (fun) solution:
10 DESTROY ALL @ RANDOMIZE PI @ OPTION BASE 1
20 FOR P=1 TO 5
30 T0=TIME @ L0=0 @ P0=0 @ DIM P0$[1000],P$[1000]
40 N=1000000 @ A=.1 @ R=.2+A @ C=0
60 FOR J=1 TO LOG10(N)
70 FOR I=10^(J1) TO 10^J1
80 T=0 @ D=1 @ L=0 @ P$=""
90 'A': IF D=1 THEN P$=P$&">" ELSE P$=P$&"<"
100 CALL PHOTON(D,T,A,R) @ L=L+1
110 IF T=P THEN C=C+1
120 IF T<P AND T>=0 THEN 'A'
130 IF T=P AND L>L0 THEN L0=L @ P0=I @ P0$=P$
140 NEXT I
150 IMAGE 2D,8D,8D,4D.2D,"% in ",5D.2D," sec LP:"
160 DISP USING 150;P,I,C,C/I*100,TIMET0,L0
170 NEXT J
180 DISP "Longest Path:";L0;"Photon:";P0
190 T=0 @ D=1
200 FOR I=1 TO L0
210 T$=STR$(T)
220 IF T<10 THEN DISP " ";
230 IF P0$[I,I]=">" THEN DISP P0$[I,I];T$; ELSE DISP T$;P0$[I,I];
240 DISP " ";
250 IF MOD(I,18)=0 THEN DISP
260 IF P0$[I+1,I+1]=">" THEN D=1 ELSE D=1
270 T=T+D
280 NEXT I
290 DISP @ DISP
300 NEXT P
310 END
320 SUB PHOTON(D,T,A,R)
330 X=RND
340 IF X<A THEN T=1 @ GOTO 380
350 IF X>R THEN 370
360 IF D=1 THEN D=1 ELSE D=1
370 T=T+D
380 END SUB
This is a lot longer that it needs to be because I wanted to track and display the longest path. The real work is done by lines 100120 and 320380. Lines 320380 take the current direction and target and randomly determine the next target and direction. Lines 100120 call PHOTON repeatedly until the target (0,1,2,...N1) is 1 (i.e. right back at you or absorbed) or N (exited on the other side).
Output:
1 10 4 40.00% in .06 sec LP: 1
1 100 76 76.00% in .22 sec LP: 1
1 1000 714 71.40% in 1.54 sec LP: 1
1 10000 7040 70.40% in 14.82 sec LP: 1
1 100000 70036 70.04% in 144.43 sec LP: 1
1 1000000 700309 70.03% in 1441.46 sec LP: 1
Longest Path: 1 Photon: 1
>0
2 10 3 30.00% in .06 sec LP: 2
2 100 60 60.00% in .33 sec LP: 2
2 1000 554 55.40% in 2.74 sec LP: 4
2 10000 5213 52.13% in 25.60 sec LP: 6
2 100000 50960 50.96% in 254.35 sec LP: 8
2 1000000 510826 51.08% in 2546.96 sec LP: 8
Longest Path: 8 Photon: 27392
>0 >1 0< >1 0< >1 0< >1
3 10 3 30.00% in .05 sec LP: 3
3 100 29 29.00% in .38 sec LP: 5
3 1000 355 35.50% in 3.66 sec LP: 9
3 10000 3714 37.14% in 35.11 sec LP:13
3 100000 37656 37.66% in 348.25 sec LP:13
3 1000000 380791 38.08% in 3485.29 sec LP:17
Longest Path: 17 Photon: 100498
>0 >1 >2 1< 0< >1 0< >1 >2 1< >2 1< 0< >1 >2 1< >2
4 10 1 10.00% in .06 sec LP: 4
4 100 34 34.00% in .49 sec LP:10
4 1000 295 29.50% in 4.32 sec LP:14
4 10000 2894 28.94% in 42.99 sec LP:16
4 100000 28728 28.73% in 428.70 sec LP:22
4 1000000 286649 28.66% in 4272.79 sec LP:24
Longest Path: 24 Photon: 228237
>0 >1 >2 1< 0< >1 >2 >3 2< 1< 0< >1 >2 >3 2< >3 2< 1<
0< >1 >2 1< >2 >3
5 10 3 30.00% in .11 sec LP: 9
5 100 14 14.00% in .61 sec LP:13
5 1000 224 22.40% in 5.31 sec LP:15
5 10000 2147 21.47% in 48.95 sec LP:21
5 100000 21485 21.49% in 490.99 sec LP:25
5 1000000 216278 21.63% in 4916.19 sec LP:37
Longest Path: 37 Photon: 743909
>0 >1 >2 >3 2< 1< 0< >1 >2 >3 >4 3< 2< 1< 0< >1 >2 >3
2< >3 >4 3< 2< 1< >2 >3 2< 1< 0< >1 >2 >3 2< 1< >2 >3
>4
10 10 1 10.00% in .11 sec LP:10
10 100 5 5.00% in .71 sec LP:12
10 1000 70 7.00% in 6.62 sec LP:26
10 10000 573 5.73% in 66.77 sec LP:44
10 100000 5638 5.64% in 662.65 sec LP:54
10 1000000 56891 5.69% in 6629.49 sec LP:60
Longest Path: 60 Photon: 146690
>0 >1 0< >1 >2 >3 2< >3 >4 3< 2< 1< >2 >3 >4 >5 4< >5
>6 5< >6 >7 6< 5< 4< 3< 2< >3 >4 >5 4< 3< >4 >5 >6 >7
6< >7 >8 >9 8< 7< 6< 5< >6 >7 6< 5< >6 >7 >8 >9 8< 7<
6< >7 >8 7< >8 >9
32 10 0 0.00% in .11 sec LP: 0
32 100 0 0.00% in .76 sec LP: 0
32 1000 1 .10% in 7.33 sec LP:44
32 10000 1 .01% in 73.61 sec LP:44
32 100000 19 .02% in 732.32 sec LP:60
32 1000000 162 .02% in 7337.15 sec LP:82
Longest Path: 82 Photon: 698717
>0 >1 >2 >3 >4 >5 >6 >7 >8 >9 >10 9< 8< 7< >8 >9 8< 7<
6< >7 >8 7< 6< 5< >6 5< 4< 3< 2< 1< >2 >3 >4 >5 >6 >7
6< 5< >6 >7 >8 >9 8< 7< >8 >9 >10 >11 >12 >13 >14 >15 >16 >17
>18 >19 >20 >21 >22 21< 20< 19< 18< 17< >18 >19 >20 >21 >22 >23 >24 >25
>26 >27 >28 >29 >30 >31 30< 29< >30 >31
The output is formated number of panes, number of transmitted photons, number of photons that made it out the other side, percentage of escaped photons, simulation time, and the current longest path.
The funny output below chronicles the journey of the photon that took the longest path (in the output directly above that would be photon 698717). The > indicates forward (< backwards) movement and the number is the target. Above photon 698717 breezed though panes 09, bounced on 10 back through 9 and 8, bounced around the high single digit numbers and eventually make a break for the low 20s, then the low 30s, and eventually emerged a bit wiser (or a wiser bit).
Comparison of calculated to simulated:
N Calculated Simulated
  
1 700000 700309
2 510417 510826
3 380266 380791
4 286687 286649
5 217596 216278
10 56721 56891
32 161 162
Thanks for the challenge.
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Egan:
Once again, an awesome effort on your part, and that makes at least two in a row, I still remember your wonderful solutions to my latest S&SMC#19 challenge.
I want to thank you for taking the trouble to create those excellent solutions in the first place and, further, take the time and considerable effort to post them here, I really do appreciate them very much, collect them for future reference, and find them extremely interesting, so thanks a lot for doing it.
If I remember correctly, you mentioned in some of your posts that you weren't all that fluent in HP71B BASIC, but it seems to me that you manage pretty well to write perfectly adequate code. Nevertheless (and please do not take this as any kind of criticism, far from it), it's true that your code could at times be optimized to take less space and run faster, which in the case of the present simulation, can make quite a difference, even if only simple optimizations are attempted.
For instance, you have this subprogram that gets called a significant number of times:
320 SUB PHOTON(D,T,A,R)
330 X=RND
340 IF X<A THEN T=1 @ GOTO 380
350 IF X>R THEN 370
360 IF D=1 THEN D=1 ELSE D=1
370 T=T+D
380 END SUB
so any savings will make a fairly noticeable, worthwhile difference. You can trivially optimize it like this:
320 SUB PHOTON(D,T,A,R) @ X=RND @ IF X<A THEN T=1 @ END
350 IF X>R THEN T=T+D ELSE D=D @ T=T+D
this version will take less memory but, more importantly, will run appreciably faster as it doesn't have any GTO's, which are really slow in HP71B's BASIC implementation, and there's also one IF statement less. Also, as you can see, no END SUB is ever necessary in a subprogram, any subprogram.
Similar trivial optimizations can be performed in a number of places with ease, which can be important for longrunning programs or when you're squeezing every available byte of RAM to accommodate large matrices.
Best regards from V.
▼
Posts: 1,619
Threads: 147
Joined: May 2006
Hello Valentin,
I initially dismissed the 71B/BASIC. I was once offered a free 71B and turned it down, but your code snippets caught my attention and ~4 months back I picked one up. Now equipped with MATH and HP41/FORTH ROMs, more RAM, and a little knowledge it is quite a machine.
Thanks for the tips. Keep them coming. Eventually I'll think BASIC, I still write prototypes in Perl or C, then port to BASIC without much thought.
OT: BTW, looking forward to your first 35s mini challenge.
Thanks again.
