Re: probability puzzle
- From: Simon Tatham <anakin@xxxxxxxxx>
- Date: 16 Sep 2007 14:11:14 +0100 (BST)
Phil Carmody <thefatphil_demunged@xxxxxxxxxxx> wrote:
An even better place to look would be Plouffe's Inverter:
Ooh, excellent, thank you. I was just saying to a friend that there
ought to be a website like that.
(`... and what's the use of sitting around telling my friends there
ought to be a website like that, if this guy just goes and gives you
its bleeding URL the next morning?' ;-)
Still doesn't recognise the number, but by this point I don't think
I really expected it to.
a = [K*2, K] + a[:n-1] + [a[n-1] + 4*a[n]]Hmmm, evidently I don't grok python well enough yet.
It's difficult to know from that which bit you don't understand, so
I'll just explain everything I can think of and hope I hit it. This
constructs a new array by concatenating three old ones:
[K*2, K] = a two-element array containing K*2 and then K (fairly obviously)
a[:n-1] = an array consisting of the first n-1 elements of a. The
absent index before the colon indicates `start at the
beginning' (I could have explicitly written a[0:n-1] and
got the same effect), and the index after the colon
indicates `stop at position n-1'. In Python expressions
of this type, the indices indicate positions _between_
elements, not elements themselves, so that the question
of inclusive or exclusive doesn't arise, and a[m:n]
always has n-m elements (assuming 0 <= m <= n < len(a)).
[a[n-1] + 4*a[n]] = a one-element array containing that value.
Thus, the result is an array a' such that
a'[0] = K*2
a'[1] = K
a'[2] = a[0]
a'[3] = a[1]
...
a'[n] = a[n-2]
a'[n+1] = a[n-1] + 4*a[n]
which is what I described in my post (modulo confusion about whether
I was talking about the value of n before or after incrementing it).
Then we use that array as the new value of a, and increment n.
--
Simon Tatham "A defensive weapon is one with my finger on the
<anakin@xxxxxxxxx> trigger. An offensive weapon is one with yours."
.
- Follow-Ups:
- Re: probability puzzle
- From: Phil Carmody
- Re: probability puzzle
- References:
- probability puzzle
- From: Brian Tung
- Re: probability puzzle
- From: Simon Tatham
- Re: probability puzzle
- From: Phil Carmody
- probability puzzle
- Prev by Date: Re: probability puzzle
- Next by Date: Re: a different twist on "Old Movie Quotes"
- Previous by thread: Re: probability puzzle
- Next by thread: Re: probability puzzle
- Index(es):
Relevant Pages
|