On the Subject of Jellybeans

Me and the boys at 3 am opening a bag of B E A N S

This module looks similar to Beans, but with a few differences. There are no beans; instead the module presents 25 jellybeans in a 5X5 array. These jellybeans are of various different colours. To solve the module, you must consume all valid jellybeans. Attempting to eat an incorrect jellybean will cause a strike. Note that you cannot see a jellybean when it has been eaten.

Finding Valid Jellybeans

Each jellybean refers to another. To find out what a jellybean refers to, take the RGB values of that jellybean (each value is between 0 and 3). If any of those values are the same, use that value for the next step. Otherwise, use the value not present for the next step. Transform the value from the previous step into a cardinal using N = 0, E = 1, S = 2 and W = 3. The current jellybean's referred jellybean is the one directly adjacent, in the cardinal direction you got. Note that the edges of the grid wrap around. A jellybean is valid if it is not referred to by any other jellybean. When a jellybean is eaten, it no longer refers to any other jellybeans.