Good to see you posting again! I have added your emailed version.

I’m sorry that you are having issues. It is a site issue and not a problem at your end.

I also looked at using lists in place of dictionaries but decided to stay with the latter.

Brian

]]>As an exercise I rewrote your code using lists instead of dictionaries. Dictionaries are definitely more intuitive in this case.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from itertools import combinations, product # consider the possible agreed values after three throws for agv in range(6, 25): # compile Nia's totals and chances of winning after one throw n2p = [0] * 9 for x in range(2, 9): for p in product((1, 2, 3, 4), repeat=4): if sum(p) + x >= agv: n2p[x] += 1 # find Nia's totals for which one is double the other for nia, p_n1 in enumerate(n2p[2:5], 2): if 0 < p_n1 < 256: # Nia's probability of winning in the second scenario p_n2 = n2p[2 * nia] # compile Rhys's totals and chances of winning after two throws r2p = [0] * 17 for x in range(4, 17): for p in product((1, 2, 3, 4), repeat=2): if sum(p) + x >= agv: r2p[x] += 1 # consider Rhys's second (lower) and first (higher) scenario totals and # chances for (r2, p_r2), (r1, p_r1) in combinations(zip(range(4, 17), r2p[4:]), 2): # the first and second scenarios give Nia a 35 times higher # chance of winning in the second compared to the first if 0 < p_r1 < 16 and 35 * p_n1 * (16 - p_r1) == p_n2 * (16 - p_r2): print(f"Agreed score {agv}; " f"Nia [{nia}:({p_n1}/256), {2 * nia}:({p_n2}/256)]; " f"Rhys [{r1}:({p_r1}/16), {r2}:({p_r2}/16)]") |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from itertools import combinations, product # consider the possible agreed values after three throws for agv in range(6, 25): # compile Nia's totals and chances of winning after one throw n2p = {x:0 for x in range(2, 9)} for x in n2p.keys(): for p in product((1, 2, 3, 4), repeat=4): if sum(p) + x >= agv: n2p[x] += 1 # find Nia's totals for which one is double the other for nia, p_n1 in n2p.items(): if 0 < p_n1 < 256 and 2 * nia in n2p.keys(): # Nia's probability of winning in the second scenario p_n2 = n2p[2 * nia] # compile Rhys's totals and chances of winning after two throws r2p = {x:0 for x in range(4, 17)} for x in r2p.keys(): for p in product((1, 2, 3, 4), repeat=2): if sum(p) + x >= agv: r2p[x] += 1 # consider Rhys's second (lower) and first (higher) scenario totals and # chances for (r2, p_r2), (r1, p_r1) in combinations(sorted(r2p.items()), 2): # the first and second scenarios give Nia a 35 times higher # chance of winning in the second compared to the first if 0 < p_r1 < 16 and 35 * p_n1 * (16 - p_r1) == p_n2 * (16 - p_r2): print(f"Agreed score {agv}; " f"Nia [{nia}:({p_n1}/256), {2 * nia}:({p_n2}/256)]; " f"Rhys [{r1}:({p_r1}/16), {r2}:({p_r2}/16)]") |