Calculator algorithm