<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>I think you are right, for some reason i read it as the repetition of a specific number, and not a repetition of any of the numbers already done.<br><br><div>> Date: Mon, 27 May 2013 00:36:46 +0200<br>> Subject: Re: [racket] A problem with Windows 8?<br>> From: olopierpa@gmail.com<br>> To: tomcoiro@hotmail.com<br>> CC: users@racket-lang.org<br>> <br>> I don't see how your function count-times implements the required algorithm.<br>> <br>> Please explain.<br>> <br>> <br>> On Mon, May 27, 2013 at 12:01 AM, Tomás Coiro <tomcoiro@hotmail.com> wrote:<br>> > I'm trying to do this Rosetta Code problem:<br>> > http://rosettacode.org/wiki/Average_loop_length<br>> ><br>> > Now, this is my code<br>> > #lang racket<br>> > (require (only-in math factorial))<br>> ><br>> > (define (analytical n)<br>> > (apply +<br>> > (build-list n (compose (lambda (x) (/ (factorial n)<br>> > (expt n x)<br>> > (factorial (- n x))))<br>> > add1))))<br>> ><br>> > (define (count-times x times)<br>> > (if (= 0 (random x))<br>> > (add1 times)<br>> > (count-times x (add1 times))))<br>> ><br>> > (define (test n times)<br>> > (/<br>> > (for/fold ((count 0))<br>> > ((i (in-range times)))<br>> > (count-times n count))<br>> > times))<br>> ><br>> > (define (test-table max-n times)<br>> > (displayln " n\tavg\ttheory\terror")<br>> > (displayln "-------------------------------")<br>> > (for ((i (in-range 1 (add1 max-n))))<br>> > (define average (exact->inexact (test i times)))<br>> > (define theory (exact->inexact (analytical i)))<br>> > (define difference (* (sub1 (/ average theory)) 100))<br>> > (displayln (format "~a\t~a\t~a\t~a%" i average theory difference))))<br>> ><br>> > (test-table 20 100000)<br>> ><br>> ><br>> ><br>> > Im not really worrying about the formatting of the output now, this is the<br>> > result.<br>> > n avg theory error<br>> > -------------------------------<br>> > 1 1.0 1.0 0.0%<br>> > 2 2.00036 1.5 33.35733333333335%<br>> > 3 3.00578 1.8888888888888888 59.12952941176472%<br>> > 4 4.00412 2.21875 80.46738028169015%<br>> > 5 5.0035 2.5104 99.31086679413636%<br>> > 6 6.00016 2.7746913580246915 116.24603337041157%<br>> > 7 7.01433 3.018138700711438 132.4058201283651%<br>> > 8 7.9905 3.2450180053710937 146.23900350550514%<br>> > 9 8.97363 3.4583157448856556 159.47977749778022%<br>> > 10 10.03618 3.66021568 174.19641019624285%<br>> > 11 10.97729 3.852372050737359 184.94885373023365%<br>> > 12 11.96714 4.036073675098951 196.50449826604333%<br>> > 13 12.96795 4.21234791295252 207.8556251283266%<br>> > 14 13.99396 4.382029424383519 219.34883691404528%<br>> > 15 15.09822 4.545807285147228 232.13506541140143%<br>> > 16 15.97676 4.704258247072678 239.62336166263555%<br>> > 17 16.99324 4.857870820801628 249.8083960412072%<br>> > 18 18.00859 5.007063098992893 259.6637318914995%<br>> > 19 18.941 5.152196200957448 267.62963329075353%<br>> > 20 20.05709 5.2935845860009 278.8942950499325%<br>> ><br>> ><br>> > the average loop length is too long, I'm worrying if the problem is my code<br>> > or if it actually is Windows 8.<br>> > I already got a different result with inexact numbers here:<br>> > http://rosettacode.org/wiki/Percentage_difference_between_images#Racket<br>> ><br>> > My question would be first, is my code wrong? (mainly "count-times")<br>> > If it isn't, do you guys get similar results? Could there be a bug in the<br>> > windows 32-bit installation for Windows 8?<br>> ><br>> > ____________________<br>> > Racket Users list:<br>> > http://lists.racket-lang.org/users<br>> ><br></div>                                            </div></body>
</html>