Created
August 14, 2010 15:54
-
-
Save offby1/524422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
#| Hey Emacs, this is -*-scheme-*- code! | |
#$Id$ | |
exec mzscheme -l errortrace --require "$0" --main -- ${1+"$@"} | |
|# | |
#lang scheme | |
;; http://programmingpraxis.com/2010/08/13/e/ | |
(define (trial) | |
(let loop ([number-of-numbers 0] | |
[sum 0]) | |
(if (<= 1 sum) | |
number-of-numbers | |
(loop (add1 number-of-numbers) | |
(+ (random) sum))))) | |
(define (main) | |
(let ([outcomes (for/list ([t (in-range 0 1000000)]) | |
(trial))]) | |
(exact->inexact | |
(/ (apply + outcomes) | |
(length outcomes))))) | |
(provide main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment