logic to calculate strings