On Mon, 07 Nov 2011 at 03:12PM -0800, Chappman wrote:
> prob.att.win.dice1 <- 0
> 
>   for (y in 2:6){
>     for (z in 1:(y-1)){
>       prob.att.win.dice1 <- prob.att.win.dice1 + probs.y[y]*probs.z[z]
>     }
>   }

I know nothing about R, but my guess is that the Sage version of the
above code is:

prob_att_win_dice1 = 0

for y in [2..6]:
    for z in [1..(y-1)]:
        prob_att_win_dice1 += probs.y[y] * probs.z[z]

You'll have to make sure that probs.y and probs.z have the right
probabilities for that to work.

Note that there's a much more compact way to do that summation: just
write

sum(probs.y[y] * probs.z[z] for z in [1..(y-1)] for y in [2..6])

(Not tested; you may need to reverse the "for y" and "for z" bits.)

I would recommend reading up on basic Python programming, which would
cover loops and so on.

Dan

--
---  Dan Drake
-----  http://mathsci.kaist.ac.kr/~drake
-------

Attachment: signature.asc
Description: Digital signature

Reply via email to