[Question]
  [
In [Wordle](https://powerlanguage.co.uk/wordle/), you try to guess a secret word, and some letters in your guess are highlighted to give you hints.
If you guess a letter which matches the letter in the same position in the secret word, the letter will be highlighted green. For example, if the secret word is `LEMON` and you guess `BEACH`, then the `E` will be highlighted green.
If you guess a letter which is present in the secret word, but not in the correct corresponding position, it will be highlighted yellow.
If a letter appears more times in the guess than it does in the secret word, only upto as many occur in the secret may be highlighted. If any of the occurrences are in the same place, they should be preferentially highlighted green, leaving earlier letters unhighlighted if necessary.
For example, with the secret `LEMON` and the guess `SCOOP`, the second `O` will be green, because it is in the right place, but the first `O` will be unhighlighted, because there is only one `O` in the secret, and one `O` has already been highlighted.
Any of the remaining letters in the secret may be highlighted yellow if they match, as long as the right number are highlighted in total. For example, with the secret `LEMON` and the guess `GOOSE`, only one of the `O`s should be highlighted; it does not matter which.
## Task
Given two five-letter strings, a secret and a guess, highlight the letters in the guess according to the rules above.
You can "highlight" the letters using any reasonable output format. For example:
* a length-`5` list of highlight values
* a list of 5 pairs of `(letter, highlight value)`
* a mapping from indices `0`-`4` or `1`-`5` to the highlight at that position
You can choose any three distinct values to represent unhighlighted, yellow, and green. (For example, `0`/`1`/`-1`, or `""`/`"Y"`/`"G"`...)
If in doubt about the "reasonable"ness of your output format, please ask. It must be unambiguous about the ordering of highlighting in case of double letters.
## Rules
* You may assume the inputs are both of length 5 and contain only ASCII letters
* You may choose whether to accept input in uppercase or lowercase
* You may take input as a string, a list of character codes, or a list of alphabet indices (in \$ [0, 25] \$ or \$ [1, 26] \$)
* You may use any [standard I/O method](https://codegolf.meta.stackexchange.com/q/2447)
* [Standard loopholes](https://codegolf.meta.stackexchange.com/q/1061) are forbidden
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins
## Test cases
All using the secret word `HELLO`: \$ \require{color} \newcommand{\qG}[1]{\colorbox{##0f0}{$ \mathtt #1 $}} \newcommand{\qY}[1]{\colorbox{##ff0}{$ \mathtt #1 $}} \newcommand{\qW}[1]{\colorbox{
##eee}{$ \mathtt #1 $}} \$
* `SCRAP` -> \$ \qW S \qW C \qW R \qW A \qW P \$
* `HELLO` -> \$ \qG H \qG E \qG L \qG L \qG O \$
* `EPOCH` -> \$ \qY E \qW P \qY O \qW C \qY H \$
* `CIVIL` -> \$ \qW C \qW I \qW V \qW I \qY L \$
* `BELCH` -> \$ \qW B \qG E \qG L \qW C \qY H \$
* `ZOOMS` -> \$ \qW Z \qY O \qW O \qW M \qW S \$ or \$ \qW Z \qW O \qY O \qW M \qW S \$
* `LLAMA` -> \$ \qY L \qY L \qW A \qW M \qW A \$
* `EERIE` -> \$ \qW E \qG E \qW R \qW I \qW E \$
* `HALAL` -> \$ \qG H \qW A \qG L \qW A \qY L \$
* `LLLXX` -> \$ \qY L \qW L \qG L \qW X \qW X \$ or \$ \qW L \qY L \qG L \qW X \qW X \$
* `LLLLL` -> \$ \qW L \qW L \qG L \qG L \qW L \$
[Copy and paste friendly format](https://ato.pxeger.com/run?1=NVBNawIxFKTX_IqHl160JDl5kEJcAi48WdG2SG-L-9wshF3YRKT9K14E8U_11zQfOiGQmfcyA3O5_Tpzvd5P_jib_728LhZv7MMQODqM5OE8jA10DiYrjVhN4DiMUFsL3pAj8OQ8HGpHjn26rm-Bp4VTb7rW2HA9NVMQSfwha4fzFOq-AZmUdiTq2a7Yqg3M3oFHsJQTqYxgelMVq0gFD4cV5VeJz2XBlhrzlEsZ6HdVrXeJijCGEMHjiyGqtUomUWdab0udf6VEhSp5Sh5NEHG_z4nyYSJkMgnI0SEs9_Wo7VnfPw)
  
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), ~~19~~ 18 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
Improved after getting some new ideas from trying this in K.
```
=+5>‚â†{‚äí‚åæ(‚àæùï®‚ä∏‚äî)Àùùï©}‚âç
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=SnVkZ2Ug4oaQID0rNT7iiaB74oqS4oy+KOKIvvCdlajiirjiipQpy53wnZWpfeKJjQoKRuKGkCJIRUxMTyLiirhKdWRnZQoKPijiiqLii4jCtyjiiL7iipHin5wi4qyc77iPIuKAvyLwn5+oIuKAvyLwn5+pIsKoKeKKuOKLiEYpwqgg4p+oCiJTQ1JBUCIKIkhFTExPIgoiRVBPQ0giCiJDSVZJTCIKIkJFTENIIgoiWk9PTVMiCiJFRVJJRSIKIkxMTFhYIgoiTExMTEwiCuKfqQ==)
---
# [BQN](https://mlochbaum.github.io/BQN/), ~~27~~ 24 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
Returns 0 for white, 1 for yellow and 2 for green.
```
+`‚ä∏√ó‚àò‚â†‚äè2‚àæ(‚â†/‚ä£)(‚äí<‚â†‚àò‚ä£)‚â†/‚ä¢
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=SnVkZ2Ug4oaQICtg4oq4w5fiiJjiiaDiio8y4oi+KOKJoC/iiqMpKOKKkjziiaDiiJjiiqMp4omgL+KKogoKRuKGkCJIRUxMTyLiirhKdWRnZQoKPijiiqLii4jCtyjiiL7iipHin5wi4qyc77iPIuKAvyLwn5+oIuKAvyLwn5+pIsKoKeKKuOKLiEYpwqgg4p+oCiJTQ1JBUCIKIkhFTExPIgoiRVBPQ0giCiJDSVZJTCIKIkJFTENIIgoiWk9PTVMiCiJFRVJJRSIKIkxMTFhYIgoiTExMTEwiCuKfqQ==)
This is a golfed version of my `Judge` function from the Wordle solver challenge, with an improvement suggested by Marshall.  
There might another approach more suitable for [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'").
This is a tacit function taking the guess on the right and the secret on the left.  
`‚â†/‚ä¢` / `‚â†/‚ä£` Remove fully correct letters from the guess / secret.  
`‚äí` Progressive indices of the shortened guess inside the shortened secret. *Progressive* means that no index is output twice and if a value is not available, the length of the vector is returned.  
`<‚â†‚àò‚ä£` For each index, is this less than the length of the shortened secret?  
`2‚àæ` Prepend a 2 to this boolean vector.  
`+`‚ä∏√ó‚àò‚â†` 0s at the green positions, positive integers in increasing order at the other positions.  
`‚äè` Index with that into the vector.
The part `+`‚ä∏√ó‚àò‚â†‚äè2‚àæ` is mostly there to invert the `‚â†/`, it would be nice if `‚â†/‚Åº` would work instead.
```
"HELLO" (‚â†/‚ä¢) "LLLXX"
# "LLXX"
"HELLO" (‚â†/‚ä£) "LLLXX"
# "HELO"
"HELO" (‚äí) "LLXX"
# ‚ü® 2 4 4 4 ‚ü©
"HELO" (‚äí<‚â†‚àò‚ä£) "LLXX"
# ‚ü® 1 0 0 0 ‚ü©
"HELLO" (+`‚ä∏√ó‚àò‚â†) "LLLXX"
# ‚ü® 1 2 0 3 4 ‚ü©
1‚Äø2‚Äø0‚Äø3‚Äø4‚äè2‚àæ1‚Äø0‚Äø0‚Äø0
# ‚ü® 1 0 2 0 0 ‚ü©
```
[Answer]
# [Perl 5](https://www.perl.org/) + `-pF`, 57 bytes
Returns `2` for green, `1` for yellow and leaves others as they were.
This example pretty prints using ANSI escape codes!
```
$_=<>;s/./$F[pos]=~s!$&!#!?2:$&/ge;eval's/$F[$-++]/1/;'x5
```
[Try it online!](https://dom111.github.io/code-sandbox/#eyJsYW5nIjoid2VicGVybC01LjI4LjEiLCJjb2RlIjoiJF89PD47cy8uLyRGW3Bvc109fnMhJCYhIyE/MjokJi9nZTtldmFsJ3MvJEZbJC0rK10vMS87J3g1IiwiaGVhZGVyIjoiIyB1c2VkIGxhdGVyIGZvciBwcmV0dHkgcHJpbnRpbmdcbiRzPSIsImZvb3RlciI6IjsjIHByZXR0eSBwcmludGluZywgcmVndWxhciBvdXRwdXQgaXMgSEVMTE8gPT4gMjIyMjIsIExMTExMID0+IExMMjJMXG5AbT0vLi9nO1xuJF89JHM7cy8uLyhcIiAkJiBcIixcIlxceDFiWzQzbSAkJiBcXHgxYlttXCIsXCJcXHgxYls0Mm0gJCYgXFx4MWJbbVwiKVskbVtwb3NdfDBdL2dlOyIsImFyZ3MiOiItcEYiLCJpbnB1dCI6IkhFTExPXG5MTFhMTCJ9)
## Explanation
Initial (implicit via `-p`) input (the target word) is stored in `$_` and split into `@F` and the guess is then stored in `$_` instead. `s///`ubstitute each letter with: if `s///`ubstituting `$&` (the current match) with `#` is successful, `2`, otherwise itself. Then `s///`ubstitute each index of `@F` left in `$_` (`s///` works on `$_` by default) with 1.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
√∏D√ÜƒÄ*√∏`0Kvy¬Æ.;
```
Input as a list of 1-based alphabet indices; modifies the list to change green to `0` and yellow to `-1` (grey values remain the same).
[Try it online](https://tio.run/##yy9OTMpM/f//8A6Xw21HGrQO70gw8C6rPLROz/r//2gLHVMdQyMwMo3lijaCcI11LGIB) or [verify all test cases](https://tio.run/##yy9OTMpM/e9YWhycbRdadminvZKChpJ9hL2SpkJiXoqCkn0lRMSxtBKowgUk/qhtElA84v/hHS6H2440aB3ekWDgXVZ5aJ2e9f9aF4jyc1uVPsyfv/LRmtlAaoVSsd6hjYdX1HoBtSvp/Pdw9fHx54pWCnYOcgxQ0lEC84G0a4C/sweQdvYM8/QB0k6uPmB@lL@/bzCQ9vFx9HUEqXMN8nQF6XP0cfQBi/tEREBoHx@lWAA).
**Explanation:**
```
√∏              # Zip the two (implicit) input-lists together, creating pairs
 D             # Duplicate this list of pairs
  √Ü            # Reduce each inner pair by subtracting
   ƒÄ           # Check for each that it's NOT 0 (0 if 0; 1 otherwise)
    *          # Multiply that to the pairs
     √∏         # Zip/transpose; swapping rows/columns
      `        # Pop and push both lists separated to the stack
       0K      # Remove all 0s from the top list
         v     # Foreach `y` over the remaining values:
          y¬Æ.; #  Replace the first `y` with -1 in the other list
               # (after which the result is output implicitly)
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 45 bytes
```
+`(\w)(.{5})\1
+$2+
+`(\w)(.*,.*)\1
-$2-
,.*
```
[Try it online!](https://tio.run/##K0otycxL/P9fO0EjplxTQ6/atFYzxpBLW8VImwsmpqWjpwUS1FUx0uUCsrn@/w92DnIM0PFw9fHx5wKTULZrgL@zB5Tt7Bnm6QNlO7n6wMWj/P19g2HqXYM8XaFsHx@fiAgE2weqFwA "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Takes input as two comma-separated words. Matching letters are changed to `+` and near-misses are changed to `-`. Explanation:
```
+`(\w)(.{5})\1
+$2+
```
Change all matching letters to `+`s (in the secret word too, so that it doesn't match later.)
```
+`(\w)(.*,.*)\1
-$2-
```
Change all near misses to `-`s.
```
,.*
```
Delete the secret word.
[Answer]
# [R](https://www.r-project.org/), ~~84~~ 80 bytes
```
function(s,g){e=s!=g;for(i in 1:5)s[x]=g[i]=1+is.na(x<-which(s*e==g[i])[1]);g*e}
```
[Try it online!](https://tio.run/##TZBRS8MwFIXf8ytifElmK01AELcIWgIrZHRsIsPSh1GaLi/paDIciL@9JiVW730797v3cO4wKrhKR3UxjdO9wTbpyFfL7Q3vlqofsIbaQPr0QGx1rXlX6ZrTO23vzRFfV@nnSTcnbBctn0akojVZdov2e3StdRZysDme8cWpx7e@MC5pMED7fPeyRcktTJ9hFgqgtZCyjBILBZDYlvk6SjTzDVBevBfy36KXXoWcqYyxIH2U5Wb/K1GPwX7wOA0@QuwKMeOTtZTycJh9WMQpizMpUfTz1wEhAISnhHDhL1NIAs@DNg6rv5w4JiLJhBAy/gA "R ‚Äì Try It Online")
My golfing skills are quite rusty after a long break, but here it goes anyway.
Takes input as a vector of codepoints, outputs 0 for exact match, 1 for inexact match, 2 - for miss (the reverse of what is given in test cases).
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), ~~32~~ 31 bytes
```
{g-(x~':x{x_x?y}\y@>g)@<>g:x=y}
```
[Try it online!](https://ngn.codeberg.page/k#eJxtj0ELgkAQhe/+imEvFbS061HK3GRBYUIxiIigk3qRgi7tIvrbc1srqmUYBubjvZlXBW1Np6qfBKpVZ7XW3UlHYT2LlmEdqJXuPG8BDOpbqefAzSwvc/BBl01zvQ+MhnY9YPrm7MWrKCCJRMyIx2Csng16HnFK4VSRXVyInHgcxvqmo9YHsx36m8o8i5OP8w+N032KhhrfP7qRaLW+66tjlm135q6TIoqtsM4OKmWRSpOIue4mAgXaRNzljIeDTfT8+o8ikgcP2GPD)
Minor reordering and syntax change from the original answer below (and it returns the negation of the one below).
---
# [K (ngn/k)](https://codeberg.org/ngn/k), 32 bytes
```
{(x~':x{x_x?y}\y@>g)[<>g]-g:x=y}
```
[Try it online!](https://ngn.codeberg.page/k#eJxtz10LgjAUBuB7f8VhNxUobV5KHy4ZKBwxEiL6oCv1Jgq6aUP0t+faKiwZY7CH855zyqAey3YUyFqe5VI1RxUuqslhtqhOXhXIuWocZwoUqnuhXGD6La4u+KCKy+X26IxZ8z5I31iGAYkFYkYcCva0tCtmIfPgWJI82vA1cRjY00Nb6YP+7G4PxTqL4m9sH6Nkm6BGHfqLK4Gm0h8YaJ9laa57DiEiT7mJ/UchNonQq9CBnjFHjmYVNhCLu51Z5TXvLyKSJ9MuYcE=)
I saw the task being discussed in the arraylang discord, so I gave it a try myself.
Returns an array where 1 represents gray, -1 green, and 0 yellow.
```
{(x~':x{x_x?y}\y@>g)[<>g]-g:x=y}   x: correct answer, y: guess
                          g:x=y    g: green positions mask (1=green)
               y@>g     reorder the guess so that greens come first
      x{     }\         seeded scan starting with x: for each char in y,
        x_x?y             delete one copy of the char from x if it exists
  x~':              for each position, test if the output is the same as input
                    (1=gray, 0=green or yellow)
 (                 )[<>g]    reorder the result back to the original position
                             (for permutation p, <p is the inverse permutation)
                         -   (1=gray, 0=other) - (1=green, 0=other)
                             = (1=gray, 0=yellow, -1=green)
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 30 bytes
Takes the guess as first argument and the secret as second. Returns a list with -1 for not highlighted, 0 for yellow and 1 for green.
```
{e-^(,/(=x@>e)@'<'=y)?<>e:x=y}
```
[Try it online!](https://ngn.codeberg.page/k#eJxFjsEKgkAQhu/7FMNeTFJyPZqWm6wojCgKEUXd1i5S0CVF7NlzXTOGuXzM989fe720bytrswracCfN0PCNoDP3/k56bdANhGxsBveX7CxwoJNN83xbMBH5ILHXO+ACC9m6vrRbmgjEnF4H4sA8n5hWUckLShjMMyJ9R1xQ9rgjEkUeJXQRFYrSY4oKKU2jg0B95S7x5zzPKpX1R4g841r8ISHKVKgSzpKVcOSoS7BFxNNJl5h+aoRIv1YVQ78=)
```
e:x=y  booleans mask with 1s where the two words are equal
         "HALAL"="HELLO" -> 1 0 1 0 0
 >     grade down; this gives an order that would sort the equal indices to the front
         > 1 0 1 0 0     -> 0 2 1 3 4
<      grade up; inverts this permutation
         < 0 2 1 3 4     -> 0 2 1 3 4
(  )?  for each of those indices, find it in the list on the left
       Returns 0N (null) for indices that are not present in the list.
         (0 1 4 0N 0N 0N)?0 2 1 3 4 -> 0 0N 1 0N 2
^      Is null? Returns a boolean mask which has 1s for non-higlighted positions. 
       ^a?b is basically "b not in a"
         ^0 0N 1 0N 2  -> 0 1 0 1 0
,/(=x@>e)@'<'=y  inner part that generates a list of indices for yellow and green highlights,
                 where the green highlights have been sorted to the front.
=y     group the secret word
         ="HELLO"    ->    "HELO"!(,0;,1;2 3;,4)
<'     grade up the indices of each group
       As the indices are sorted within each group,
       this converts each to a range from 0 to length-1.
         <'="Hello"  ->    "HELO"!(,0;,0;0 1;,0)
x@>e   sort matching values to the front in the guessed word.
         "HALAL"@>1 0 1 0 0 -> "HLAAL"
=      group this reordered string
         ="HLAAL" -> "HLA"!(,0;1 4;2 3)
Now we have two dictionaries:
  - "char in secret!0 .. number of times that char appears-1",
  - "char in guess!indices of that char, when greens are sorted to the front"
@'     pair up matching keys in the two dicts,
       and apply @ between their values.
       @ performs indexing, where out of bounds indices return nulls.
       when a key is only present in one of the dicts,
this will generate a new one with a list of nulls as value.
         ("HLA"!(,0;1 4;2 3))@"HELO"!(,0;,0;0 1;,0) -> "HLAEO"!(,0;1 4;,0N;,0N;,0N)
,/     flatten the values into a list
         ,/"HLAEO"!(,0;1 4;,0N;,0N;,0N) -> 0 1 4 0N 0N 0N
```
[Answer]
# [Haskell](https://www.haskell.org/), 112 bytes
```
import Data.List
f(x:y,z)=[0^x|elem x z]:f(y,delete x z)
f _=[]
x?z|x==z=(0,0)|1>0=(x,z)
((f.unzip).).zipWith(?)
```
[Try it online!](https://tio.run/##Hcu9CsMgFIbh3atw6HAEEdOfJXCapWP3DmKLUE0kPw2JBSO5d5uUb3h5hq8xc2u7Lmffj58p0JsJRtz9HIiDWC48MVTyGVfb2Z5GmnTpYOHvjcHuZsTRFypNYpXWiJgQJJdsLa4SIW53UiOAE98h@ZEJJrY8fGigYrk3fsBx8kM41FSd@L6CXzRVBT/@ddb5Bw "Haskell ‚Äì Try It Online")
Takes input as a list of integers on the range \$[1,26]\$. Outputs a list of `[]` for no match `[1]` for perfect match and `[0]` for imperfect match.
This feels like it could be shorter. Having to import `delete` is costly.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), ~~52~~ ~~46~~ 45 bytes
```
{@[g;&[#'(=x)^\:&g;#'y]#'y:(=y)^\:&g:x=y;2+]}
```
[Try it online!](https://ngn.codeberg.page/k#eJxFjlELgjAUhd/3K8YELRJSHyeCSwYKVyYKIZm9qS9S0EuOqN/e5ky5XC58nHPu6ek7bobQbixnF03725XaQ2g5slVLd5E0hE6RDIND+0HoiD08PDvpYl/f7u7iAMtuHB8v1MeUpBxAEOThZb49qZKSFQT5eBmFFlWgFPMqxAuRpJtRoyQ7Z6CRthl04mBUwRp/ESKvdNaGAFjOjPGPOC8zrkt4a1bKgIEp4a9GqGtTYv5pEAD5AU5RRXw=)
-1 byte from ngn (thanks!).
Starting with a list of positions showing letters that do (green `1`) and don't (grey `0`) match in the secret and guess, amend it as follows:
Ignoring the positions that are green, take the first n positions of each letter in the guess (where n is the fewer of the frequency of that letter in the secret versus in the guess), and add `2` to those positions (yellow).
[Answer]
# [Python 3](https://docs.python.org/3/), 113 bytes
```
lambda g,w:[g[i]-w[i]and~((g[:i]+[a-b or b for a,b in zip(w,g)][i:]).count(g[i])<w.count(g[i]))for i in range(5)]
```
[Try it online!](https://tio.run/##TU67bsMwDNz5FUImsXW8FF2M5ksUDbQt2wRoSZDc2snQX3elqVkOdyTuER/bEvzHedzup9Daj6TmZu/MbNhe9wLkx1@tZ9OxfTd07VVIqldTQWp6xV49Oeq9mdEa7iy2Q/j2m652/NpfFVYPV0ciPzv9ifacbi@dhzZvK0Ud0ljjmn@1o0UAXmNIm8qPDFCzpGYV1eZtZN8mR6Owd1ljByomLsVSfqnsw2Z64ZfFiYQL4pmHRBFcDMMCA/@wQO@k8GcIawYp4wicS@xgISEpFzmOiiJ/ "Python 3 ‚Äì Try It Online")
Uses `-1` for gray, `-2` for yellow and `0` for green. A further 3 bytes can be saved if `-1` is replaced by False and `-2` by True, but I dislike this output format, since `False==0`.
Input is a list of charcodes
[Answer]
# JavaScript,  ~~76b~~  ¬†  ~~72b~~  ¬† 69b
Solution found by @subzey and me while golfing the [MiniWordle](https://xem.github.io/MiniWordle/) project.
Thanks to @emanresu for the further improvements
```
// a is the correct word (array of letters)
// b is the guessed word (array of letters)
a=>b=>b.map((s,i)=>s==a[i]?a[i]=0:s).map(s=>s?a[x=a.indexOf(s)]=~x:1)
```
Returns an array of 5 digits. 0 = black, 1 = green, anything else = yellow
For example: `f([..."TEETH"])([..."EERIE"]) == [-3, 1, 0, 0, 0]`
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 29 bytes
```
{u+^?/{x@&'x=,\x}'x*\:u:~=/x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxNjs0KgzAQhO8+hc2htrXgT28p0qYSUFiJKBRptUefQCEl6LPXTQLpLnv5mJmdkao5/NwiJe/7QGbnXi6BPPV0pmsWycXzJqq+62WXhOOBFBxAkKs8Lt70Jm3esJoMsW8XmVEMiW8XGa9FXpAh3TT6kOXlswTn1ezBAXWxdlr2EqJqkaXuBwCrGOb9Mc6bkhuv68KAAXaJXR4AdJ3pkri8bUwX/fkHNjdA5Q==)
in: `("HELLO";guessedword)`, out: `0`=[bull](https://en.wikipedia.org/wiki/Bulls_and_Cows), `1`=cow, `2`=neither
`{` `}` function with implicit argument `x`
`~=/x` mask of where letters of the two words differ
`u:` assign to `u`
`x*\:` multiply by each left - zero out the matching letters
`{` `}'` map
`,\x` prefixes (of one of the words)
`x=,\x` masks of where letter x[i] occurs in x[0...i]
`&'x=,\x` where (masks -> lists of indices)
`x@&'x=,\x` indexing of x with the above, i.e. for any letter `"a"`, the first occurrence turns into `,"a"` (a string of length 1), the second occurrence into `"aa"`, the third into `"aaa"`, etc.
let's call the above *rep-letters* for "replicated letters"
`?/` for each rep-letter of the guessed word, find its position among the rep-letters of the secret word; for "not found", use the special null value `0N`
`^` mask of nulls
`u+` add to `u`
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 33 bytes
```
‚≠ÜŒ∏‚éá‚ÅºŒπ¬ßŒ∑Œ∫+¬ß.-‚Äπ‚ÑñÔº•‚Ä¶Œ∏Œ∫‚ÅªŒª¬ßŒ∑ŒºŒπ‚ÑñÔº•Œ∑‚ÅªŒª¬ßŒ∏ŒºŒπ
```
[Try it online!](https://tio.run/##bYxNCsIwFIT3niJk9YKpF3CloVAhRUEvEGIwoTG1@RF7@ph2EwQfDI8ZZj6phZejsDlfvHERrrG8Ry9eMFF0U94JP0M7JWEDGIoO8eTu6gOaooEQivAW1xDvmuK4CgHYmApswbBZWsX0uAKHMumNSwHsD@tJFpgpqkP9pzrV6nr7nI8tZ92mazk/5@Ztvw "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Outputs `+` for exact match, `-` for near miss and `.` for mismatch. Explanation:
```
 Œ∏                                  Guessed word
‚≠Ü                                   Map over letters
    Œπ                               Current letter
   ‚Åº                                Equal to
      Œ∑                             Secret word
     ¬ß                              Indexed by
       Œ∫                            Current index
  ‚éá                                 If true then
        +                           Literal string `+` else
          .-                        Literal string `.-`
         ¬ß                          Indexed by
             ‚Ññ                      Count of
                       Œπ            Current letter in
                Œ∏                   Guessed word
               ‚Ä¶                    Truncated to length
                 Œ∫                  Current index
              Ôº•                     Map over letters
                   Œª                Inner letter
                  ‚Åª                 Remove match of
                     Œ∑              Secret word
                    ¬ß               Indexed by
                      Œº             Inner index
            ‚Äπ                       Is less than
                        ‚Ññ           Count of
                                Œπ   Current letter in
                          Œ∑         Secret word
                         Ôº•          Map over letters
                            Œª       Inner letter
                           ‚Åª        Remove match of
                              Œ∏     Guessed word
                             ¬ß      Indexed by
                               Œº    Inner index
                                    Implicitly print
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 63 bytes
```
s=>g=>g.map((u,i)=>s[i]-u&&s.some((v,j)=>g[j]==v|u-v?0:s[j]=1))
```
[Try it online!](https://tio.run/##pZDNisIwFEb3PkVWJgEb1KVDKk4JYyFSURicKV2UWPuDGknazGbevZOMFlxHCOG7B869N2lyk2uh6lsbXOWx6E@01zQs7SGX/IZQN6kxDXVaZ0E3Hmui5aVAyEwaS8u0ySg1v11gltOFdtUM4/5HquM8VwpQ4CKgIUgJIS5n/01F5ZioiKhyFdmpqxZhPFJFOxeV02waLBvvknHEXpSCKVgC@AHB4lG3qisc@nIIAojfRkJetTwX5CxL9OiLTmjYDME14zyBGD@hfbRbbS2ym3jYA/Kz2TaJ1t52FH/G3Nt@Z/yF2d9Jstn7v5vtYuZtc84Ph1dsfv@1/g8 "JavaScript (Node.js) ‚Äì Try It Online")
Input array of code points, Output array of 0 = Green, true = Yellow, false = Unhighlighted.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~125~~ ~~122~~ 117 bytes
```
#define F for(i=5;i--;)g[i]
i;f(s,g,p)char*s,*g,*p;{F==s[i]?s[i]=1,g[i]=2:0;F,(p=index(g,s[i]))?*p=3:0;F>3?g[i]=4:0;}
```
[Try it online!](https://tio.run/##tVPBbtpAEL3zFSOqBBuMGiA5FNfhUBV@oQisylnWy9LFtjxO6ybi10Nn7DUyhEq91Ah4O/Pe7Oy@sRgqIY7HDxsZ60TCHOI0d3Tw4Ovh0HfVSocd7ccOesrLXLGN8j56feX1M/91HgRI@Rn/BCOPucF4eufPPScLdLKRpaM8TrrurJ8FE049TmYV754Wh6NOCthHOnFceO0APSJNsIBqGygkFvgdVyEE8NrdSmPSrgf/Cxz8vzSgbAMo8ig7E8osFVsGQv/UhsGTNHXkJU33yMCYaB9VZJlrWckjE5k6ZcrSAmOuNSDLTIpCbmwHnAYWLPhhsAT6MOBMDRYLC5aWvGwALBo5WM6SQ7WcZNc6EFspfsjcNrAuv47X5acv9H1gWWs9adQ0PuCwr9UAkOzOt/AzoH6RaexYY92Pdt1vAj4MBhXXrUrVI3HZElLNZjQqcuhf5akTT73jZTl1GDtdlCKXxRTW3Rtc04nUs0RsljB85MtBCrutLag4PD3HMZXFIjcycZQLAxiF1zjYcPCSQ3GR/XbqSudbtFO0O7ZS8SlaC93rZ5d09tPwXB6ezcki5HsctSrza0@ZXW3Zju1a7UK2ZOe2rGgqsLX2GnY0HQGMYQa9RW96xmyeM@aEmct/Yd4zE3pT6H3r@Wd0e4Dq7/YWpBWUFyzr840gI8vWZR3ejQKQ5QmxmonnyqFVHDqH45uITaTwOPz1Bw "C (gcc) ‚Äì Try It Online")
*Saved 5 bytes thanks to [tsh](https://codegolf.stackexchange.com/users/44718/tsh)!!!*
Inputs a secret and a guess as two strings.  
Returns the "highlights" as a list of \$2\$s, \$3\$s, and \$4\$s in the second input string.  
With \$2\$ for green, \$3\$ for yellow, and \$4\$ for unhighlighted.
[Answer]
# [J](http://jsoftware.com/), 39 31 bytes
```
=(+{.e.&(,.1#.%=%\)/@i.])=|"1,:
```
[Try it online!](https://tio.run/##ddH/a4JAFADw3/0rHm2lR3pmY78cnGTiKLhmNBhR@YO4qzlEh9lGLPrXnV82sXbzOJB3H997vnvLO1jeAiUggwoDIMXWMNgL9pBTpf@FOe4pKjZucJd2N0gfhdhD9NQxVJIDPI4xSAo9rZFC@yE@N9gk1CQb5NXak67ompTy/lYnI50gvWCqStSziCrlIWrzMiCk7QY86m1Qj5ikaQFJJU4O2fshIzAECruU81gFo3g98ihKPssBlGH/WNkdZKkf7yM/43sI4@I72CYpBEn8weOQxwEnlauPIp5lPN2Dppng74MwLOALl3YUw7an3PUOBEkSD14TkFn5yEV@eeIw5sp1eNAs0IrreLIX1vwPGjarQvXRNTKKHPWukDN37cm/5X6QPX2einoqSzVo7DBhJqPd@Mp1ZytBTxeIMWtmCcu1kOMspo5gBIN2TxOLWUw4gmG7HFsuhSOo/@8XXVxL/g0 "J ‚Äì Try It Online")
*-8 bytes thanks to Bubbler!*
The above is Bubbler's excellent golf of the "alternate idea" I included in my original post:
```
(~:*[)(=+i.~e.&(,.1#.]=]\)&:>:]i.])~:*]
```
# [J](http://jsoftware.com/), 37 bytes
```
<@(~:*[)(_*])`i.`[} ::[~&.>/@,~~:<@*]
```
[Try it online!](https://tio.run/##ZZFvb9owEMbf51Oc9oIQBm7y1v2jpCgTkdxRUWmqilAw4QB3wYkSp4NJ46szGwhtQNZJlu93d89zft9/I/YC7inY0AUXqI4egf6I/djf@e0d7YyddtyZOFNBpuN/QOl41yIPN353t6N3fmeyd6yfjwSWoAouy5QrLCEawiIrIMnkB0qBMkEKQuaVghSVwqKEXu8BvJ6Qc9wAT/MVn6ECWa1nOkkAskoZ2lCVnGUbnJ@eiLW8JzCmcAuLVtv7Hpja@D1uCeJYByF6vgJeltVaC3FBlJBjscBEwZqrZAXtZYEonS7EhxwvlOBpndtimmZ/dJLLuY4t5FkplPjAkzZTIrPPTnzraLWRlp4Va56Kv3qmWiHwRFW668mGMhW/EXCTax1nL4C8FLqnThfI58Qy0o07wGSV@T1qfLY9Op2Yxet7RPTX@EhaLsQOLG/8iWUZFOxBwAJm60@wByFjQ9vyoD6Hfdgv/VHwrH@YngkX6nMkjs9fiVhXH@NIhM/D/qBB1DNqoh/9itgFYSZ8Eo8hu@oRN5S@DYdPbxc6mgRjwVNwNeUrEYajKLxw6zV0nBZ24dZtTGGvr1duj27OBGv02P8H "J ‚Äì Try It Online")
* Input: 1-indexed integers representing index within the alphabet.
* Output: boxed list with the following scheme:
	+ `0` = green
	+ `_` = yellow
	+ positive integers = gray
## idea
* Turn perfect matches of both target and guess into 0 by multiplying by the "not-equal" vector `~:`.
* Starting with the guess as our "previous value", reduce the letters of the target as follows:
	+ If target letter not found in guess, return guess unaltered
	+ If target letter found, update the first matching index of the guess to infinity `_`. This both "marks" the yellow partial match and ensures the same index won't be found again.
	+ If letter found is a 0 (ie, already marked as a perfect match), update it to 0 (ie, leave it unchanged). Ensures that the reduction only touches yellow matches.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 78 bytes
```
a=>b=>b.map(y=(x,i)=>x-(c=a[i])&&(y[c]=-~y[c]*2,x)).map((x,i)=>x&&!(y[x]>>=1))
```
[Try it online!](https://tio.run/##nZDBCoJAEIbvvUUX24lcqKusYLKSuKEoRCQetk3KKI2UWC@9um1FRN1cGBj4@L8ZZo78xmtxLS6NWVa7vPNIx4m9VYXP/IJaguSkAGJLEwnC0yIDw0BtKjJi3p9tPJtIgFf2kzSMoUrIzLbJFKCzAiIVxeLAr65a4TQIrIGoyro65fhU7ZGHUozxaEEZC0fZa1YA8IaJGzvRF/Yw/2APk0ahu9AyXX/lMy1zTpnmzk0YLhO9O2nsUy2TMbZe65rs50PdAw "JavaScript (Node.js) ‚Äì Try It Online")
Input charcode/[1,26], output `true`(no), `0`(green), `false`(yellow)
# [JavaScript (Node.js)](https://nodejs.org), 82 bytes
```
a=>b=>b.map(y=(x,i)=>x!=(c=a[i])&&(y[c]=-~y[c],x)).map((x,i)=>x&&~~y[x]&&!!y[x]--)
```
[Try it online!](https://tio.run/##jc9RC4IwEAfw976FL3MDty8QE0omCouJQkjiw1oShjnJiPnSV1@a@D44OP7cj@PuIT9yVK92eONe3xobUytpeJ2LPOUAJwpN0CIaGo9CRWXV1ggAOFWqpvi7tMAg9KcbBOA7D0wNgOctHWNk9zul@1F3Den0HcawIoT4CeNc@DVaUxHlh2xOyMFuycWyTESJo43Sc8od7ZFx570XIU6F670sT5mj5ZyXpbvl62/2Bw "JavaScript (Node.js) ‚Äì Try It Online")
`0`(no match), `false`(green), `true`(yellow)
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 92 bytes
Returns a list of `-1` for *Green*, `False` for *Yellow* and `True` for not highlighted.
```
lambda*r,c='':[-(a==b)or(c:=c+b).count(b)>sum(y!=x==b for x,y in zip(*r))for a,b in zip(*r)]
```
[Try it online!](https://tio.run/##TU9NSsQwGN3PKWI2ScY4GzdSiKAlMIVIhxmQwXEWTWy14jTlawut4hm8gDBbBQ/gebyA3qAmrQtX73s/8N5XdvWdLY5PSugzcd0/JDt9k0yBG0FIsDmiiRCaWaAmEOZQs5mxTVFTzU6rZke7A9E6H2UWUMs7lBfoMS/pFBjzUsL1P2nbV6mBtEYC4blUKsYTH7pt0qryMbwKl2cLzP9MjuUiDucOw@gyUg7PpRr4VRxfrLwvl5F0qJRar0dUCgcThMB1ZHSs40MBc2oJuZs@UE7I7N7mBcU/@/3b18fr9@eLu97xpt2O3/hFwHhG6BM8M8L6Xw "Python 3.8 (pre-release) ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~18~~ 17 bytes
```
o@=
√ßW;≈ì-\‚Åª∆ù ã√ß@+=
```
[Try it online!](https://tio.run/##y0rNyan8/z/fwZbr8PJw66OTdWMeNe4@NvdU9@HlDtq2/x/u2ARkPGpaE/n/f7BzkGOAgoerj4@/gmuAv7OHgrNnmKePgpOrD5Ad5e/vG6zg4@Po66jg6hrk6arg4ejj6AMU8YmIAJE@Pv/BegE "Jelly ‚Äì Try It Online")
*-1 because there was a completely extraneous `…ó`*
Target on left, guess on right; `0` for gray, `1` for yellow, `2` for green.
Absolutely dreadful... There ought to be some sort of `=√æ`-based solution, but I've had no luck yet.
```
o@=    Dyadic helper link: mask out exact matches
  =    For each pair of corresponding elements, are they equal?
o@     Replace 0s with elements from the left argument, leaving 1s unchanged.
√ßW;≈ì-\‚Åª∆ù ã√ß@+=    Main link
√ß                Mask matches out of the target,
         √ß@      mask matches out of the guess,
         ã        and with those on the left and right:
 W;  \           Scan across the guess, starting with the masked target, by
   ≈ì-            multiset difference;
       ∆ù         for each pair of adjacent scan results,
      ‚Åª          are they not equal?
           +=    Add that to the mask of exact matches.
```
[Answer]
# [Julia 1.6](https://julialang.org), 72 bytes
```
a\b=(* =.==;c=a*b;b[c]=a[c].=0;c-[sum(b[i]b[1:i])>sum(b[i]a) for i=1:5])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY5BSsNAFIb3c4rXWWVqOlixIA1TiGEggSkpLUhxOoskTWFKnEraQC7g2gMotJuCggfwKt16AT2CmUY3___e__g_3stxXRU6ORyO1W7VuzmFySJlThcYZczLWNJNvVRmiiWNUHbpZT25rR6cVGqVyv5QKzL63xMCq00JmvWHA0X-eE-dGhhI_PXx-v35jF38s9-_tfaO3Wt3oOTVRa0QstUatIEyT5aFNvnWIQgAynM95ELEmFKqFrK2Zk-PpTa7wji1CxjYCLAL6402Du2UxEY2KAnKzbJ95nDyZ8HUn6AzDfFJHIQoiO4igW65aOb7OB7PkBD-2EecTyOOQl_4oknEfG5ViJb0Cw)
Fixed and improved version of [mbeltagy's answer](https://codegolf.stackexchange.com/a/242816/98541)
Needs version 1.6+ for `(*) = (.==)`. [73 bytes in Julia 1.0](https://tio.run/##TYxBSgMxGIX3OcXfrCY4BkfspiWFOARmIGVKC1JMs8hMR0gZU0kt5BZeQOhWwQN4Hi@gNxgndePmvcf3eG937KzJQt@bTc2ShhnKWD2tVaOZGYSyq2lzqQ7Hx6RWVsdSZROryewfMgQe9h4syyZjTfpRAAYKf328fn@@4BT/nE5vf/aO05t0rNX1RdAIxU0A68C3ZttZ1x4SggDAn@eFkLLClFK9USFarJ68dc@dS0IKGNgMcAq7vXUJHXkSUQSeoNZt@1W@5At0fkFiUeUFysu7UqJbIYd8X1XzFZKSzzkSYlkKVHDJ5UDkeh1Vyl8 "Julia 1.0 ‚Äì Try It Online")  
Inputs are vectors of characters, and the output is a vector with `1` for green, `0` for yellow, and `-1` for uncolored
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `t`, ~~24~~ ~~23~~ 21 bytes
```
Z‚Å∞¬π-·∏É*‚à©√∑$¬£0o(¬•nu√∏·∏û¬£)¬•
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJ0IiwiIiwiWuKBsMK5LeG4gyriiKnDtyTCozBvKMKlbnXDuOG4nsKjKcKlIiwiIiwiWzgsNSwxMiwxMiwxNV1cblsyLDUsMTIsMyw4XSJd)
or [Run all the test cases](https://vyxal.pythonanywhere.com/#WyJ0UCIsIkBmOng6eXzihpB4OsKj4oaQeTrihpIiLCJawqXihpAt4biDKuKIqcO3JMKjMG8owqVudcO44biewqMpwqUiLCI7XG5cbkMgNjQtIOKBsEzhuosgJCBDIDY0LSBaIOKGkmFcbuKGkGEg4oaQYSDGmyDDtyBAZjsgOyBaIMabIMO3ICQgOiA2NCsgQyB24bmFIFogxpsgw7cgYCAoYCBKICQgUyBKIGApYCBKOyBgIGFuZCBgIGogJCA6IMabIDA9W2Dwn5+pYHx1PVtg8J+fqGB8YOKsm2BdXSA7IOG5hSAkIFMgYCAoYCBKICQgSiBgKWAgSiBcIiBgID0+IGAgaiA7IOKBiyIsIkhFTExPXG5bXCJTQ1JBUFwiLFwiSEVMTE9cIixcIkVQT0NIXCIsXCJDSVZJTFwiLFwiQkVMQ0hcIixcIlpPT01TXCIsXCJMTEFNQVwiLFwiRUVSSUVcIixcIkhBTEFMXCIsXCJMTExYWFwiLFwiTExMTExcIl0iXQ==) (it took me way longer to write the code to run the test cases than the program itself lol)
Port of 05AB1E answer. Can probably be golfed down a ton.
*-1 byte thanks to Aaroneous Miller*
[Answer]
# [Python 2](https://docs.python.org/2/), 95 bytes
```
lambda g,t:[not a or a in t and t.remove(a)for a in[a[a==b:]or t.remove(a)for a,b in zip(g,t)]]
```
[Try it online!](https://tio.run/##XU/BToQwEL3zFZN4aGsqB48kHJDUQNKVza4xG5FDyRZE2UKgmF2N345T2JNzmHmdN/Pmtb/Y987cz1X4NrfqVB4V1NwGueksKOgGTI0BxOYI1h/0qfvSVLHqyuQqV2FYBgW@/9O8dKvfTU9RkRXF/KkvgBHCz1NndEBuCX9U7YjojvDnYUJwQ379WlvPqgELjpJESJkRzynWkx5Hp0n28S7awkKB2GZxAnH6kkp4EBLxa5Zt9iBltIlAiF0qIIlkJLEjDweXpST@2LeNpSzwAAY9Tq07VtG2GS1d7jC@4NUIYzjWD425khzWPgdC/I@uMRT/Rs8MnM2zs7hqMjb/AQ "Python 2 ‚Äì Try It Online")
Loops over the guess twice, while removing characters from the target. Direct matches are removed in the first loop, indirect matches in the second. Requires two `list`s as input. Outputs a `list` containing 5 elements: `True` for direct match, `None` for indirect match and `False` for no match.
]