First pass at creating the calc logic function

Doing it in a playground to verify logic before moving to a real
project.