knuth

generating poisson variables in c++

守給你的承諾、 提交于 2019-12-06 03:27:27
问题 I implemented this function to generate a poisson random variable typedef long unsigned int luint; luint poisson(luint lambda) { double L = exp(-double(lambda)); luint k = 0; double p = 1; do { k++; p *= mrand.rand(); } while( p > L); return (k-1); } where mrand is the MersenneTwister random number generator. I find that, as I increase lambda, the expected distribution is going to be wrong, with a mean that saturates at around 750. Is it due to numerical approximations or did I make any

How does division work in MIX?

≡放荡痞女 提交于 2019-12-06 03:23:23
问题 Can someone explain to me how division in MIX (from TAOCP by Knuth) works on a byte-to-byte basis? rA = |-| . . . .0| rX = |+|1235|0|3|1| The memory location 1000 contains |-|0|0|0|2|0| . When you execute the operation DIV 1000 the registers become rA = |+|0|617|?|?| rX = |-|0|0|0|?|1| Now I understand the signs on rA and rX , but in what order are the bytes of rAX filled and which divisions are done? If DIV 1000 leads to every bit divided by 2, then I would expect rAX = |+|617|0|1|0|-|0|1|0

Sorting 5 elements with minimum element comparison

坚强是说给别人听的谎言 提交于 2019-12-05 09:41:44
I have to model the execution plan of sorting a list of 5 elements, in python, using the minimum number of comparisons between elements. Other than that, the complexity is irrelevant. The result is a list of pairs representing the comparisons needed to sort the list at another time. I know there's an algorithm that does this in 7 comparisons (between elements, always, not complexity-wise), but I can't find a readable (for me) version. How can I sort the 5 elements in 7 comparisons, and build an "execution plan" for the sort? PD: not homework. This fits your description of sorting 5 elements in

Unable to combine English words from letters by Ruby

折月煮酒 提交于 2019-12-04 19:42:33
I need to find all English words which can be formed from the letters in a string sentence="Ziegler's Giant Bar" I can make an array of letters by sentence.split(//) How can I make more than 4500 English words from the sentence in Ruby? [edit] It may be best to split the problem into parts: to make only an array of words with 10 letters or less the longer words can be looked up separately glenra [Assuming you can reuse the source letters within one word]: For each word in your dictionary list, construct two arrays of letters - one for the candidate word and one for the input string. Subtract

How does division work in MIX?

纵饮孤独 提交于 2019-12-04 07:38:57
Can someone explain to me how division in MIX (from TAOCP by Knuth) works on a byte-to-byte basis? rA = |-| . . . .0| rX = |+|1235|0|3|1| The memory location 1000 contains |-|0|0|0|2|0| . When you execute the operation DIV 1000 the registers become rA = |+|0|617|?|?| rX = |-|0|0|0|?|1| Now I understand the signs on rA and rX , but in what order are the bytes of rAX filled and which divisions are done? If DIV 1000 leads to every bit divided by 2, then I would expect rAX = |+|617|0|1|0|-|0|1|0|1|1| in which rA contains the division results and rX the remainders (filled from the right side). I'm

Knuth the art of computer programming ex 1.1.8

こ雲淡風輕ζ 提交于 2019-12-04 07:02:47
I can't figure out what Knuth meant in his instructions for an exercise 8 from Chapter 1.1. The task is to make an efficient gcd algorithm of two positive integers m and n using his notation theta[j] , phi[j] , b[j] and a[j] where theta and phi are strings and a and b - positive integers which represent computational steps in this case. Let an input be the string of the form a^mb^n . An excellent explanation of Knuth's algorithm is given by schnaader here . My question is how this may be connected with the direction given in the exercise to use his Algorithm E given in the book with original r

The Art of Computer Programming exercise question: Chapter 1, Question 8

耗尽温柔 提交于 2019-12-03 06:39:29
I'm doing the exercises to TAOCP Volume 1 Edition 3 and have trouble understanding the syntax used in the answer to the following exercise. Chapter 1 Exercise 8 Computing the greatest common divisor of positive integers m & n by specifying T j ,s j ,a j ,b j Let your input be represented by the string a m b n (m a's followed by n b's) Answer: Let A = {a,b,c}, N=5. The algorithm will terminate with the string a gcd(m,n) j T j s j b j a j 0 ab (empty) 1 2 Remove one a and one b, or go to 2. 1 (empty) c 0 0 Add c at extreme left, go back to 0. 2 a b 2 3 Change all a's to b's 3 c a 3 4 Change all

WordCount: how inefficient is McIlroy's solution?

喜欢而已 提交于 2019-11-30 03:43:33
Long story short: in 1986 an interviewer asked Donald Knuth to write a program that takes a text and a number N in input, and lists the N most used words sorted by their frequencies. Knuth produced a 10-pages Pascal program, to which Douglas McIlroy replied with the following 6-lines shell script: tr -cs A-Za-z '\n' | tr A-Z a-z | sort | uniq -c | sort -rn | sed ${1}q Read the full story at http://www.leancrew.com/all-this/2011/12/more-shell-less-egg/ . Of course they had very different goals: Knuth was showing his concepts of literate programming and built everything from scratch, while

WordCount: how inefficient is McIlroy's solution?

我只是一个虾纸丫 提交于 2019-11-29 00:40:44
问题 Long story short: in 1986 an interviewer asked Donald Knuth to write a program that takes a text and a number N in input, and lists the N most used words sorted by their frequencies. Knuth produced a 10-pages Pascal program, to which Douglas McIlroy replied with the following 6-lines shell script: tr -cs A-Za-z '\n' | tr A-Z a-z | sort | uniq -c | sort -rn | sed ${1}q Read the full story at http://www.leancrew.com/all-this/2011/12/more-shell-less-egg/ . Of course they had very different goals