Hints for Programming Assignment 3 (Cipher)

Computing chisqr:

Consider

os = [7, 5, 3, 2]
es = [1, 9, 8, 3]

chisqr value is computed as follows:

  chisqr(os,es)
= 0 + (7 - 1)(7 - 1)/1 + (5 - 9)(5 - 9)/9 + (3 - 8)(3 - 8)/8 + (2 - 3)(2 - 3)/3
= 0 + 36 + 16/9 + 25/8 + 1/3
= 41.236

Computing the list of chisqr values in chisquare_statistic function

To computer the chi-square statistic list of values, you need to compute the chi-square value as above for each rotation of os by n positions, where n ranges from 0 to 25. i.e. you need to calculate the following 26 values:
chisqr(rotate(os,0), es)
chisqr(rotate(os,1), es)
chisqr(rotate(os,2), es)
chisqr(rotate(os,3), es)
...
...
chisqr(rotate(os,25), es)
and return these values in a list in the function chisquare_statistic.