How to resolve the algorithm Wordle comparison step by step in the Tailspin programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Wordle comparison step by step in the Tailspin programming language

Table of Contents

Problem Statement

While similar to both Bulls and cows and Mastermind, Wordle is a notable variation, having experienced a viral surge in popularity, and reverse engineering the game or creating variants has become a popular programming exercise. However, a sampling of the "code a Wordle clone" videos on YouTube shows that seven of the eight reviewed had a serious flaw in the way that they assigned colours to the letters of a guessed word. This aspect of the game is described here: en.wikipedia.org/wiki/Wordle#Gameplay Create a function or procedure that takes two strings; the answer string, and the guess string, and returns a string, list, dynamic array or other ordered sequence indicating how each letter should be marked as per the description above. (e.g. "green", "yellow", or "grey", or, equivalently, the integers 2, 1, or 0 or suchlike.) You can assume that both the answer string and the guess string are the same length, and contain only printable characters/code points in the ASCII/UniCode Range ! to ~ (hex 20 to 7F) and that case is significant. (The original game only uses strings of 5 characters, all alphabetic letters, all in the same case, but this allows for most existing variants of the game.) Provide test data and show the output here. The test data should include the answer string ALLOW and the guess string LOLLY, and the result should be (yellow, yellow, green, grey, grey) or equivalent.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Wordle comparison step by step in the Tailspin programming language

Source code in the tailspin programming language

templates wordle
  sink removeFirst
    @: $;
    @wordle: [$@wordle... -> #];
    when <=$@> do ''! @:'';
    otherwise $!
  end removeFirst
  @: [$(1)...];
  [$(2)...] -> \[i](
    when <=$@wordle($i)> do (green:$)! @wordle($i): '';
    otherwise $!
  \) -> \[i](
    when <'' ?($@wordle <[<=$>]>)> do (yellow:$)! $ -> !removeFirst
    when <''> do (grey:$)!
    otherwise $!
  \) !
end wordle

test 'wordle'
  assert ['ALLOW', 'LOLLY'] -> wordle <=[(yellow:'L'), (yellow:'O'), (green:'L'), (grey:'L'), (grey:'Y')]> 'guess LOLLY'
  assert ['ALLOW', 'STALL'] -> wordle <=[(grey:'S'), (grey:'T'), (yellow:'A'), (yellow:'L'), (yellow:'L')]> 'guess STALL'
  assert ['ALLOW', 'ALLEY'] -> wordle <=[(green:'A'), (green:'L'), (green:'L'), (grey:'E'), (grey:'Y')]> 'guess ALLEY'
  assert ['ALLOW', 'ALLOW'] -> wordle <=[(green:'A'), (green:'L'), (green:'L'), (green:'O'), (green:'W')]> 'guess correct'
end 'wordle'

['ALLOW', 'LOLLY'] -> wordle -> !OUT::write

  

You may also check:How to resolve the algorithm 24 game step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Quickselect algorithm step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Test a function step by step in the Lasso programming language
You may also check:How to resolve the algorithm Remove duplicate elements step by step in the Oberon-2 programming language
You may also check:How to resolve the algorithm Main step of GOST 28147-89 step by step in the Phix programming language