This is a sorting problem, which is an kind of applied mathematics.
Insertion sort: Gnomes arrive one-by-one. The first two gnomes stand next to each other. The third gnome stands between the first two if the third gnome sees two different colored hats, otherwise the third gnome goes to the end of the line (after the second gnome). Each newly arriving gnome inserts himself between the two gnomes with different colored hats or goes to the end of the line if all of the gnomes in line have the same color hat.
Some jostling is needed to make room for the newly arriving gnomes in the insertion sort method. This jostling is a kind of communication, just not talking. I assume that jostling and other physical contact is allowed. Therefore,
Heap sort: The gnomes all meet in the clearing. The chief tells the gnomes they are to take any punches they receive like a gnome. He then tells the gnomes to pummel all the gnomes they see wearing red hats into unconsciousness and pile them in a heap. When the brawl ends, the chief gnomes counts all the standing gnomes (the blue group) and the unconscious gnomes (the red group).