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