eight coin algorithm