Find multiple identical items in an array

Hi, so Im working on setting materials from items in an array. It checks to see if a number is in the array and if so set the material based on the index. The issue I have is when the random "Code Answer" (Between 0000-9999) contains multiple of the same numbers e.g. 7783 the 2nd duplicate number does not set a material which makes sense. I'm struggling to come up with an efficient solution (other than using 4 branches each time) whereby I can assign the next index to a different material.

https://preview.redd.it/m1z6x5do87de1.png?width=1893&format=png&auto=webp&s=c7ad9589d7b8dc64065227b25abfd64896713648