Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code to call your function: %Input arguments must be in the following order: target word, guess word x = wordle('query', 'chore') display_wordle('chore', x) figure y=wordle('query',

image text in transcribed

Code to call your function:

%Input arguments must be in the following order: target word, guess word

x = wordle('query', 'chore')

display_wordle('chore', x)

figure

y=wordle('query', 'quiet')

display_wordle('quiet', y)

figure

y = wordle('block', 'broom')

display_wordle('broom', y)

%************************************

% No need to modify this function

% It displays the result graphically

% with the color code:

% green = correct letter

% yellow = letter is in the word

% grey = letter is not in the word

%************************************

function display_wordle(guess, letter_vals)

%initialize to white

disp_array = ones(1,5,3);

for k = 1:5

switch letter_vals(k)

case 1

%letter matches - make it green

disp_array(1,k,:) = [0,1,0];

case 0

%letter is in the word - make it yellow

disp_array(1,k,:) = [0.75,0.75,0];

case -1

%letter is not in the word - make it grey

disp_array(1,k,:) = 0.5;

end

end

imshow(imresize(disp_array, 50, 'nearest'));

for k = 1:5

text(10+50*(k-1), 25, upper(guess(k)), 'fontsize', 36, 'color', 'w');

end

end

Wordle scoring The latest word game craze is Wordle, in which a player tries to guess a 5-letter word and, after each guess. is provided with feedback about which letters are correct. Write a function, named wordle, that takes two CHARACTER ARRAYS as inputs: the target word, and the player's guess. The function should compare the two and return a 1x5 numerical: For each letter in the guess, set the corresponding value in the numerical array as follows: If that letter matches the letter in the same position of the target word, +1 If that letter is in the target word, but not in the same position, 0 (Hint: a relational operator with the sum function is the easiest way to do this.) If that letter is not in the target word, -1 So, for example, if the target word is 'clump' and the user guess is 'chill', the function should return [1, -1, -1, 0, 0] Note: This is a simplified version of Wordle scoring that doesn't handle the case of multiple occurrences of a letter correctly. For example, if the target word = "block", and the guess = "broom", this function will return [1,-1, 1, 0, -1], whereas in the real game it would be [1, -1, 1, -1, -1]. For a challenge, you can try implementing the more complete scoring, but for the tests used in this problem, the result will be the same. Function Reset MATLAB Documentation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions