Super proud of the golf I just made on my Prolog answer
here. My previous solution was actually incorrect, caused by the predicate that was supposed to only find the index of a list element also appending it to the list if it wasn't in there already (Prolog is so much fun). The way it was doing it was mostly correct so I was able to tweak it so the lookup up predicate was also doing the job of the code that was supposed to handle the appending.