Re: [LUAU] doing 'e'
I just tried it again with both Firefox and IE and it doesn't load. It looks like a dns problem - it can't find the server, and nslookup doesn't work either. Strange...I tried another online NS Lookup tool at http://www.zoneedit.com/lookup.html? host=www.programmingebooks.tk&type=A&server=&forward=Look+it+up and got three IP addresses that didn't work, either. Can somebody else test this link? This is kind of wierd. http://www.programmingebooks.tk/ Not working for me either. G4 Apple laptop Road Runner connection Firefox and Safari
Re: [LUAU] doing 'e'
--- Jim Thompson <[EMAIL PROTECTED]> wrote: > > > Robert Green wrote: > > >--- Jim Thompson <[EMAIL PROTECTED]> wrote: > > > > > > > >>Doug, of course, is a long-standing member of the Unix community. > >>(And thanks, I didn't know about "The Music of Streams". > >> > >>Here is a large collection of programming "e-books". > >>http://www.programmingebooks.tk/ > >> > >>just in-case anyone is getting the itch. > >> > >> > > > >This link didn't work -- has the site moved? I tried a couple of > >google's and ketp getting 'not found' errors > > > > > > > hmm, loaded fine for me (just now) on a firefox/ubuntu system. > > jim > > ___ > LUAU@lists.hosef.org mailing list > http://lists.hosef.org/cgi-bin/mailman/listinfo/luau > I just tried it again with both Firefox and IE and it doesn't load. It looks like a dns problem - it can't find the server, and nslookup doesn't work either. Strange...I tried another online NS Lookup tool at http://www.zoneedit.com/lookup.html?host=www.programmingebooks.tk&type=A&server=&forward=Look+it+up and got three IP addresses that didn't work, either. Can somebody else test this link? This is kind of wierd. __ Yahoo! DSL Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com
Re: [LUAU] doing 'e'
damn, now we just need an erlang implementation. http://www.erlang.org/course/course.html (funny that nobody stepped to the plate with perl) Tim Newsham wrote: Here it is in haskell. This shows some of the strengths of haskell, but also some of its weaknesses. Dealing with random numbers is more tedious than it should be. Some of the awkwardness could be caused by the programmer's lack of experience with the language. - e.lhs - Literate haskell for computing "e" the hard way. Translated from lisp code by Jim Thompson (see e.lisp) module E where import Time import System.Random Some siliness so that the random numbers are different for each run. randomSeed :: IO Int randomSeed = do -- XXX Could be a lot better. t <- getClockTime >>= toCalendarTime return $ hashStr $ show t where hashStr s = foldl hashAdd 0 $ map fromEnum s hashAdd a b = (a*13) + b A sum is the accumulation from 0. We call it sum' because there's already an integer sum function. A list of accumulated sums is made by keeping each intermediate sum value. sum' = foldl (+) 0.0 sums = scanl (+) 0.0 Average of a list is its sum divided by its length. average x = sum' (map fromIntegral x) / (fromIntegral $ length x) length of series items whose sum does not exceed 1.0. waitTime x = length $ takeWhile (< 1.0) (sums x) A number of waitTimes drawn from successive items in x. waitTimes x 0 = [] waitTimes x n = let wt = waitTime x in wt : waitTimes (drop wt x) (n - 1) putLine x = putStr $ (show x) ++ "\n" main :: IO () main = do seed <- randomSeed let variates = randoms $ mkStdGen seed mapM_ putLine $ [average $ waitTimes variates n | n <- [1,10,100,1000]] Tim Newsham http://www.lava.net/~newsham/ ___ LUAU@lists.hosef.org mailing list http://lists.hosef.org/cgi-bin/mailman/listinfo/luau
Re: [LUAU] doing 'e'
Here it is in haskell. This shows some of the strengths of haskell, but also some of its weaknesses. Dealing with random numbers is more tedious than it should be. Some of the awkwardness could be caused by the programmer's lack of experience with the language. - e.lhs - Literate haskell for computing "e" the hard way. Translated from lisp code by Jim Thompson (see e.lisp) module E where import Time import System.Random Some siliness so that the random numbers are different for each run. randomSeed :: IO Int randomSeed = do -- XXX Could be a lot better. t <- getClockTime >>= toCalendarTime return $ hashStr $ show t where hashStr s = foldl hashAdd 0 $ map fromEnum s hashAdd a b = (a*13) + b A sum is the accumulation from 0. We call it sum' because there's already an integer sum function. A list of accumulated sums is made by keeping each intermediate sum value. sum' = foldl (+) 0.0 sums = scanl (+) 0.0 Average of a list is its sum divided by its length. average x = sum' (map fromIntegral x) / (fromIntegral $ length x) length of series items whose sum does not exceed 1.0. waitTime x = length $ takeWhile (< 1.0) (sums x) A number of waitTimes drawn from successive items in x. waitTimes x 0 = [] waitTimes x n = let wt = waitTime x in wt : waitTimes (drop wt x) (n - 1) putLine x = putStr $ (show x) ++ "\n" main :: IO () main = do seed <- randomSeed let variates = randoms $ mkStdGen seed mapM_ putLine $ [average $ waitTimes variates n | n <- [1,10,100,1000]] Tim Newsham http://www.lava.net/~newsham/
Re: [LUAU] doing 'e'
Robert Green wrote: --- Jim Thompson <[EMAIL PROTECTED]> wrote: Doug, of course, is a long-standing member of the Unix community. (And thanks, I didn't know about "The Music of Streams". Here is a large collection of programming "e-books". http://www.programmingebooks.tk/ just in-case anyone is getting the itch. This link didn't work -- has the site moved? I tried a couple of google's and ketp getting 'not found' errors hmm, loaded fine for me (just now) on a firefox/ubuntu system. jim
Re: [LUAU] doing 'e'
--- Jim Thompson <[EMAIL PROTECTED]> wrote: > > Doug, of course, is a long-standing member of the Unix community. > (And thanks, I didn't know about "The Music of Streams". > > Here is a large collection of programming "e-books". > http://www.programmingebooks.tk/ > > just in-case anyone is getting the itch. This link didn't work -- has the site moved? I tried a couple of google's and ketp getting 'not found' errors Aloha, Rob __ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs
Re: [LUAU] doing 'e'
Why the lucky stiff has created a beautiful interactive ruby lesson [it doesn't work very well in Safari yet; try Firefox]. http://tryruby.hobix.com/ See his notes on what people try to do with it: http://redhanded.hobix.com/inspect/205000LinesOfRubyCodeDonatedInTheTryRubyDrive.html
Re: [LUAU] doing 'e'
On Wed, Nov 30, 2005 at 06:56:48AM -1000, Jim Thompson wrote: > Lets see a perl/python/... equivalent to this lisp exercise for > obtaining 'e': I will pass on perl, but here is my attempt in ruby. I would have made it more functional/lisp-like, but I have not fully grokked using yield. #! /usr/bin/env ruby class Array def avg inject { |sum, n| sum + n } / length.to_f end end def wait_time sum, times = 0, 0 while sum <= 1.0 sum += rand times += 1 end times end def wait_times(trials) list = [] trials.times do |t| list.push wait_time end list end def avg_wait_time(trials) wait_times(trials).avg end puts 'Some wait times: ' + wait_times(10).join(' ') trials = [ 1, 10, 100, 1000, 1, 10 ] print 'Average wait times:' trials.each do |t| print ' ' + avg_wait_time(t).to_s end Visit http://tryruby.hobix.com/ for an amazingly interactive tutorial to ruby. -Vince
Re: [LUAU] doing 'e'
Doug, of course, is a long-standing member of the Unix community. And of course inventor of the unix pipe: http://cm.bell-labs.com/cm/cs/who/dmr/mdmpipe.pdf http://cm.bell-labs.com/cm/cs/who/dmr/mdmpipe.html One of many great historical tidbits on Ritchie's home page. A must-read for anyone interested in unix or computing history: http://cm.bell-labs.com/who/dmr/ Tim Newsham http://www.lava.net/~newsham/
Re: [LUAU] doing 'e'
Tim Newsham wrote: Lets see a perl/python/... equivalent to this lisp exercise for obtaining 'e': [...] Euler's number, 'e', is approximately 2.7182818284590452354, and this is a highly-inefficient way to extract it, but the function does tend toward 'e'.) Jim If you like this kind of stuff, you'd probably get a kick out of Doug McIlroy's "The Music of Streams", available on his home page: http://www.cs.dartmouth.edu/~doug/ Doug, of course, is a long-standing member of the Unix community. (And thanks, I didn't know about "The Music of Streams". Here is a large collection of programming "e-books". http://www.programmingebooks.tk/ just in-case anyone is getting the itch.
Re: [LUAU] doing 'e'
Lets see a perl/python/... equivalent to this lisp exercise for obtaining 'e': [...] Euler's number, 'e', is approximately 2.7182818284590452354, and this is a highly-inefficient way to extract it, but the function does tend toward 'e'.) Jim If you like this kind of stuff, you'd probably get a kick out of Doug McIlroy's "The Music of Streams", available on his home page: http://www.cs.dartmouth.edu/~doug/ I toyed with the code in python a little: http://lava.net/~newsham/x/machine/powerseries.py http://lava.net/~newsham/x/machine/powerseries2.py but neither is as elegant as his (pseudo-) haskell implementation Heres your python code: #!/usr/bin/python import random uniform = random.random # gratuitous rename def waitTime() : """Return the number of uniform variates whose sum just exceeds 1.""" sum,times = 0,0 while sum <= 1.0 : sum,times = sum+uniform(), times+1 return times def repeat(n, f, *args, **kwargs) : """Return the results of running a function n times.""" return [f(*args, **kwargs) for n in xrange(n)] def average(l) : """ Return the average of a list. Raise an exception for empty lists. """ return float(sum(l)) / len(l) # show some waitTime results print "Some waitTimes", repeat(10, waitTime) # show averages for increasing lengths of repeat(waitTime) print "average waitTimes", [average(repeat(n, waitTime)) for n in 1, 10, 100, 1000, 1, 10] Tim Newsham http://www.lava.net/~newsham/
[LUAU] doing 'e'
Jim Thompson wrote: or lisp (setq service_list (mapcar #'string-downcase TempServiceList)) Lets see a perl/python/... equivalent to this lisp exercise for obtaining 'e': * (defun uniform () "the uniform random variable on the interval (0,1)" (random 1.0 )) UNIFORM * (defun wait-time (&optional ignore-me) "the number of uniform random variates when their sum first exceeds 1" (do ((count 0 (1+ count)) (total 0 (+ total (uniform ((> total 1) count))) WAIT-TIME ;; I put the optional parameter in wait-time to support this use: * (mapcar #'wait-time '(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)) (2 2 2 2 2 2 2 3 3 4 3 2 4 3 2) ;; The wait-times are smallish integers. Let's try to see what their average is. * (defun avg-wait-time (trials) (let ((sum 0)) (dotimes (i trials) (incf sum (wait-time))) (/ sum trials 1.0))) AVG-WAIT-TIME ;; Can you guess the limiting value of the average wait time? * (mapcar #'avg-wait-time '(1 10 100 1000 1 10 100)) (2.0 2.9 2.71 2.726 2.7118 2.71774 2.719146) * (mapcar #'avg-wait-time '(1 10 100 1000 1 10 100 1000)) (2.0 3.0 2.77 2.71 2.7093 2.72287 2.717509 2.7183373) * (mapcar #'avg-wait-time '(1 10 100 1000 1 10 100 100)) (2.0 2.9 2.72 2.721 2.7164 2.71576 2.71782 2.7182744) Euler's number, 'e', is approximately 2.7182818284590452354, and this is a highly-inefficient way to extract it, but the function does tend toward 'e'.) Jim