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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Wordle comparison step by step in the FutureBasic 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 FutureBasic programming language

Source code in the futurebasic programming language

short x = 80, y = 20

clear local fn colorString( w1 as str15, w2 as str15 ) as str15
  str255 n : str15 c : c[0] = w2[0] : short r
  for r = 1 to w1[0]
    if w2[r] = w1[r] then c[r] = 2 else n[w1[r]]++
  next
  for r = 1 to w2[0]
    if c[r] == 0 then if n[w2[r]] then n[w2[r]]-- : c[r] = 1
  next
end fn = c

mda(0) = {fn ColorDarkGray,fn ColorWithRGB(.7,.6,.3,1),fn ColorWithRGB(.3,.6,.3,1)}
void local fn wordleCompare( wordle as str15, guess as str15 )
  str15 color : short r
  color = fn colorString( wordle, guess )
  text @"menlo bold", 14, fn colorLightGray
  print %( 20, y ) wordle : text ,,fn colorWhite
  for r = 1 to guess[0]
    rect fill ( x, y, 24, 24 ), mda_object( color[r] )
    print %( x + 7.5, y + 1 ) chr$( guess[r] ); : x += 28
  next
  x = 80 : y += 28
end fn

window 1, @"FB Wordle Compare", ( 0, 0, 265, 290 )
WindowSetBackgroundColor( 1, fn Colorblack )
fn wordleCompare( "ALLOW", "LOLLY" )
fn wordleCompare( "CHANT", "LATTE" )
fn wordleCompare( "ROBIN", "SONIC" )
fn wordleCompare( "PROUD", "LEAST" )
fn wordleCompare( "STEAL", "LEAST" )
fn wordleCompare( "LEAST", "LEAST" )
fn wordleCompare( "FULLY", "LABEL" )
fn wordleCompare( "We're", "She's" )
fn wordleCompare("LONGER", "STRING")

handleevents

  

You may also check:How to resolve the algorithm Euler's sum of powers conjecture step by step in the Raku programming language
You may also check:How to resolve the algorithm Synchronous concurrency step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the Seed7 programming language
You may also check:How to resolve the algorithm 15 puzzle game step by step in the Picat programming language
You may also check:How to resolve the algorithm QR decomposition step by step in the BBC BASIC programming language