public
Created

  • Download Gist
gistfile1
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#! /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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.