# Trettels:Session 1 - 16JAN

Session 2: 16 JAN 2013
Code for Question 2 (written in MATLAB):
Group: TrettelS, TSanders, LIan, RCardenas

Part 1:

clear all; close all; clc;
range = [1 exp(1) pi 4 5 6 exp(pi)]; % the value weights for each side
range=cumsum(range/sum(range)); % builds our numberline
% roll the first die...
t_base = rand(1,1e6);
t1(t_base <=range(1))=1;
t1(t_base>range(1) & t_base <= range(2))=2;
t1(t_base>range(2) & t_base <= range(3))=3;
t1(t_base>range(3) & t_base <= range(4))=4;
t1(t_base>range(4) & t_base <= range(5))=5;
t1(t_base>range(5) & t_base <= range(6))=6;
t1(t_base>range(6) & t_base <= range(7))=7;
% and roll the second
t_base=rand(1,1e6);
t2(t_base <=range(1))=1;
t2(t_base>range(1) & t_base <= range(2))=2;
t2(t_base>range(2) & t_base <= range(3))=3;
t2(t_base>range(3) & t_base <= range(4))=4;
t2(t_base>range(4) & t_base <= range(5))=5;
t2(t_base>range(5) & t_base <= range(6))=6;
t2(t_base>range(6) & t_base <= range(7))=7;
%find out how many of our results add to 8
result1=sum(t1+t2==8)

Result was 62239

Part 2: What is the analytic expectation for 1,000,000 rolls?

We will take advantage of the fact that for $n$ rolls, $n*E[$ one roll sums to 8$] = n*\sum_{k=1}^{k_{max}} p(k)*p(k_{max}-k)$, where $k_{max}=7$.

range2 = [1 exp(1) pi 4 5 6 exp(pi)];
range2 = range2/sum(range2);
p_8 = 1e6 *sum(range2(1:7).*range2(7:-1:1))

Result is (approximately) 62377.04196435287