Algorithm for calculating pattern values written. Still needs work though.