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 k ≠ j, 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
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
Problem Comments
Solution Comments
Show comments
Problem Recent Solvers87
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!