(71B) Buffon's Needle
09-08-2019, 04:00 PM
Post: #1
 SlideRule Senior Member Posts: 1,254 Joined: Dec 2013
(71B) Buffon's Needle
An extract from Buffon, [kiyoshiakima url]

"2 Simulation Programs
Buffon's Needle can be implemented easily on all but the smallest HP programmable
2.2 BASIC
For the HP-71B the following BASIC program simulates the experiment. It prompts for the number of ten-throw trials, then prints the occurrences of each outcome and an estimate for π.
10 DESTROY ALL @ OPTION BASE 0 @ RADIANS @ DIM R(11) @ P=0
20 INPUT N @ FOR I=1 TO N
30 H=0 @ FOR J=1 TO 10 @ IF RND()<SIN(RND()*PI) THEN H=H+1
40 NEXT J @ R(H)=R(H)+1 @ P=P+H
50 NEXT I
60 FOR I=0 TO 10 @ PRINT I;R(I) @ NEXT I
70 PRINT 20*N/P"

BEST!
SlideRule
09-08-2019, 09:54 PM
Post: #2
 Valentin Albillo Senior Member Posts: 654 Joined: Feb 2015
RE: (71B) Buffon's Needle
(09-08-2019 04:00 PM)SlideRule Wrote:  30 H=0 @ FOR J=1 TO 10 @ IF RND()<SIN(RND()*PI) THEN H=H+1
40 NEXT J @ R(H)=R(H)+1 @ P=P+H

You will get a syntax error entering line 30, it's just RND, without the parentheses, not RND().

Also, it should run somewhat faster if you include the NEXT J also in line 30, like this:

30 H=0 @ FOR J=1 TO 10 @ H=H+(RND<SIN(RND*PI)) @ NEXT J

(written and posted on the go using a tablet, still not at my laptop)

Regards.
V.
.

Find All My HP-related Materials here:  Valentin Albillo's HP Collection

09-09-2019, 07:20 AM
Post: #3
 J-F Garnier Senior Member Posts: 468 Joined: Dec 2013
RE: (71B) Buffon's Needle
(09-08-2019 09:54 PM)Valentin Albillo Wrote:
(09-08-2019 04:00 PM)SlideRule Wrote:  30 H=0 @ FOR J=1 TO 10 @ IF RND()<SIN(RND()*PI) THEN H=H+1
40 NEXT J @ R(H)=R(H)+1 @ P=P+H

You will get a syntax error entering line 30, it's just RND, without the parentheses, not RND().

Actually, RND(), with parentheses, is a valid syntax on the HP71, as for other functions without argument. Even PI can be entered as PI() since PI is a function from the HP71 system point of view.

J-F
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)