Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Luca Saiu Newsgroups: comp.lang.forth Subject: Happy pi approximation day Date: Sun, 21 Jul 2013 22:45:22 +0200 Organization: A noiseless patient Spider Lines: 35 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx05.eternal-september.org; posting-host="934abd412aadcefb5191f2649343499a"; logging-data="11748"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19F6VsEpi7vpR8ffdB4Ko6+C8DtjfmHSUI=" User-Agent: Gnus (Ma Gnus v0.8), GNU Emacs 24.3.50.1, x86_64-unknown-linux-gnu X-Accept-Language: en, fr, it Cancel-Lock: sha1:s7jCj44wpD9U1fOpBbUIgnJNIvY= X-GPG-FINGERPRINT: 14DC 72EB 19F7 D2E6 C12E 113C BF33 9ABE 26C5 D286 X-Home-Page: http://ageinghacker.net X-GPG: 0x26C5D286 Xref: csiph.com comp.lang.forth:24650 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