Problem 61060. Popular Word Game™ Distance

Professor Ned, who holds the Nedowed Chair of Crackpot Mathematics at the University of Nedsburg, has recently discovered the daily word puzzle Popular Word Game™ published by the Nedsburg Times. He has become so obsessed with it, he is trying to pioneer a whole new field of math based around the idea of a Popular Word Game distance metric: the distance between two points x and y is calculated using the rules of Popular Word Game to score x as a guess for the solution y.
In Popular Word Game, the elements, x(j), of x (which would be letters in the game) are scored using these rules:
  • If x(j) = y(j), then x(j) is shown as green (correct)
  • Otherwise, if x(j) = y(k) for some kj, then x(j) is shown as yellow (correct value/letter, but wrong location)
  • Elements of y can be used only once as a match
  • Precedence goes first to green matches, then to yellow
  • Evaluation goes in index order (left to right)
  • Otherwise, x(j) is shown as black (incorrect)
In Professor Ned's metric, the elements of x are assigned numeric values according to these same rules, with green = 0, yellow = 1, black = 2. The distance between x and y is then the sum of these individual distance values.
Example
Diagram showing how the distance is calculated for an example with x = [4 3 2 4 2 3 1] and y = [3 1 2 4 1 4 4]. First, the third and fourth elements of x and y are matched and shown as green. Then the first element of x (4) is matched to the sixth element of y. The second element of x is matched to the first element of y. The seventh element of x is matched to the second element of y. These are all shown as yellow. The remaining elements of x are shown unmatched. The two green elements score 0, the three yellow elements score 1 (each), and the two black elements score 2 (each), for a total of 7.
x = [4 3 2 4 2 3 1];
y = [3 1 2 4 1 4 4];
d = PWGdist(x,y)
d =
7
Assumptions
The vectors x and y will be nonempty numeric row vectors of the same length.

Solution Stats

52.75% Correct | 47.25% Incorrect
Last Solution submitted on Nov 16, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers38

Suggested Problems

More from this Author33

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!