Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #24650
| From | Luca Saiu <positron@gnu.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Happy pi approximation day |
| Date | 2013-07-21 22:45 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <kshgui$bf4$3@dont-email.me> (permalink) |
Happy pi approximation day, Forthers.
s" random.fs" included
10000000 constant sampleno
10000 constant n
: square
dup * ;
n square constant nsquare
: coordinate
n random ;
: below ( x y -- b )
square swap square + nsquare ( y²+x² n² ) < ;
: 1sample ( u -- v )
coordinate coordinate below if 1+ endif ;
: countbelow ( u -- v )
0 swap 0 u+do 1sample loop ;
: go ( -- denominator numerator )
sampleno dup countbelow 4 * ;
go . . cr bye
When explaining this, I've seized the occasion to write a little
tutorial for non-Forthers on my blog, at
http://ageinghacker.net/blog/posts/13 . Of course I welcome comments
from you experts.
Regards,
--
Luca Saiu
Home page: http://ageinghacker.net
GNU epsilon: http://www.gnu.org/software/epsilon
Marionnet: http://marionnet.org
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar
Happy pi approximation day Luca Saiu <positron@gnu.org> - 2013-07-21 22:45 +0200
Re: Happy pi approximation day Coos Haak <chforth@hccnet.nl> - 2013-07-22 01:24 +0200
Re: Happy pi approximation day Coos Haak <chforth@hccnet.nl> - 2013-07-22 01:27 +0200
Re: Happy pi approximation day Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-22 01:14 -0700
Re: Happy pi approximation day Luca Saiu <positron@gnu.org> - 2013-07-22 11:53 +0200
Re: Happy pi approximation day anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-22 15:46 +0000
Re: Happy pi approximation day albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-22 19:18 +0000
Re: Happy pi approximation day Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-07-22 21:17 +0100
Re: Happy pi approximation day "Elizabeth D. Rather" <erather@forth.com> - 2013-07-22 11:25 -1000
counted loops (was: Happy pi approximation day) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-23 12:42 +0000
Re: counted loops "Elizabeth D. Rather" <erather@forth.com> - 2013-07-23 07:24 -1000
Re: counted loops anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-23 17:33 +0000
Re: counted loops "Elizabeth D. Rather" <erather@forth.com> - 2013-07-23 08:06 -1000
Re: counted loops albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-23 19:47 +0000
Re: counted loops "Elizabeth D. Rather" <erather@forth.com> - 2013-07-23 10:02 -1000
Re: counted loops Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-23 14:58 -0500
Re: counted loops "Elizabeth D. Rather" <erather@forth.com> - 2013-07-23 10:14 -1000
Re: counted loops anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-24 08:13 +0000
Re: counted loops Elizabeth D Rather <erather@forth.com> - 2013-07-23 22:42 -1000
Re: counted loops stephenXXX@mpeforth.com (Stephen Pelc) - 2013-07-24 09:55 +0000
Re: counted loops stephenXXX@mpeforth.com (Stephen Pelc) - 2013-07-24 09:37 +0000
Re: Happy pi approximation day albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-23 01:30 +0000
Re: Happy pi approximation day "Elizabeth D. Rather" <erather@forth.com> - 2013-07-22 19:08 -1000
Re: Happy pi approximation day m.a.m.hendrix@tue.nl - 2013-07-23 00:19 -0700
Re: Happy pi approximation day anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-23 13:07 +0000
Re: Happy pi approximation day albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-23 17:37 +0000
Re: Happy pi approximation day anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-23 12:31 +0000
Re: Happy pi approximation day Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-07-23 19:39 +0100
Re: Happy pi approximation day anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-24 08:16 +0000
Re: Happy pi approximation day Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-24 04:23 -0700
Re: Happy pi approximation day albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-24 11:59 +0000
Re: Happy pi approximation day Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-24 21:32 +0200
Re: Happy pi approximation day albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-24 20:07 +0000
Re: Happy pi approximation day Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-24 23:20 +0200
Re: Happy pi approximation day m.a.m.hendrix@tue.nl - 2013-07-22 01:30 -0700
Re: Happy pi approximation day Luca Saiu <positron@gnu.org> - 2013-07-22 11:55 +0200
Re: Happy pi approximation day albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-22 11:24 +0000
Re: Happy pi approximation day Richard Owlett <rowlett@pcnetinc.com> - 2013-07-22 10:48 -0500
Re: Happy pi approximation day Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-22 14:44 -0500
Re: Happy pi approximation day Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-24 00:43 -0700
Re: Happy pi approximation day Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-24 03:07 -0500
csiph-web