In reply to Hans-Ulrich.

The solution I posted above counts the ties.