<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Wordle on R Views</title>
    <link>https://rviews.rstudio.com/tags/wordle/</link>
    <description>Recent content in Wordle on R Views</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 21 Feb 2022 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://rviews.rstudio.com/tags/wordle/" rel="self" type="application/rss+xml" />
    
    
    
    
    <item>
      <title>Wordle Data Analysis</title>
      <link>https://rviews.rstudio.com/2022/02/21/wordle-data-analysis/</link>
      <pubDate>Mon, 21 Feb 2022 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2022/02/21/wordle-data-analysis/</guid>
      <description>
        
&lt;script src=&#34;/2022/02/21/wordle-data-analysis/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;&lt;em&gt;Arthur Holtz is a Senior FP&amp;amp;A Manager at Shipt, but don’t let the title mislead you — he spends most of his days buried in databases and R, analyzing data. This post is neither affiliated with nor endorsed by his employer.&lt;/em&gt;&lt;/p&gt;
&lt;div id=&#34;intro&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Intro&lt;/h1&gt;
&lt;p&gt;By now, I’m sure most people are familiar with the viral game &lt;a href=&#34;https://www.nytimes.com/games/wordle/index.html&#34;&gt;Wordle&lt;/a&gt;. If you’ve been living under a rock and have no idea what I’m talking about, I recommend playing it for yourself. The best way I can describe it is: Take the classic board game &lt;a href=&#34;https://en.wikipedia.org/wiki/Mastermind_(board_game)&#34;&gt;Mastermind&lt;/a&gt;, but play with words instead of colored pegs. It’s a fun little game that encourages sharing and comparing scores with your friends – which I think explains a lot of its popularity!&lt;/p&gt;
&lt;p&gt;Speaking of comparing scores, my wife routinely gets a better score than I do, so I’ve been trying to come up with better strategies. A few weeks ago, YouTube recommended &lt;a href=&#34;https://www.youtube.com/watch?v=v68zYyaEmEA&#34;&gt;3Blue1Brown’s fantastic video&lt;/a&gt; on information theory and Wordle strategy. After watching it, I felt inspired. I could do something along those lines! Granted, I’m nowhere near as sophisticated as the creator of that video, but I thought it would be a fun challenge to crack open the game’s script and see what I could do with its data. With all the background out of the way, let’s jump into it!&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;getting-started&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Getting Started&lt;/h1&gt;
&lt;p&gt;First, we will need to include a number of libraries for this analysis. Most of these should be familiar to anyone who works with R regularly so I won’t add more color here.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;suppressMessages({
library(httr)
library(dplyr)
library(stringr)
library(ggplot2)
library(ggthemes)
library(scales)
library(tidyr)})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From the 3B1B video, I found out you can view the code powering Wordle simply by viewing the page source in your browser and finding the JavaScript. As of writing, that code is &lt;a href=&#34;https://www.nytimes.com/games/wordle/main.18637ca1.js&#34;&gt;here&lt;/a&gt;. Now, I’ll admit, I don’t know much of anything about JavaScript, but that doesn’t really matter – the word list is stored in plain text as an array.&lt;/p&gt;
&lt;p&gt;If you look through the code, you might notice there are actually 2 word lists: The first, called &lt;code&gt;Ma&lt;/code&gt;, is a list of 2,309 words that Wordle uses for puzzle solutions (there used to be 2,315 but apparently the &lt;a href=&#34;https://www.gamespot.com/articles/the-nyt-has-now-officially-changed-the-wordle-solution-list/1100-6500735/&#34;&gt;NYT removed a few&lt;/a&gt;). The second list, called &lt;code&gt;Oa&lt;/code&gt;, is a list of words it will accept as valid guesses. Since &lt;code&gt;Oa&lt;/code&gt; has a lot more obscure words that will never show up as the answer, for this exercise, I am focusing entirely on &lt;code&gt;Ma&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The first thing I do is simply download the &lt;code&gt;.js&lt;/code&gt; file and save it as a giant string of text, which I’m calling &lt;code&gt;wordle_script_text&lt;/code&gt;. In the event the script or domain name ever changes, all you need to do is paste in the new URL here.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;url = &amp;quot;https://www.nytimes.com/games/wordle/main.18637ca1.js&amp;quot;
wordle_script_text = GET(url) %&amp;gt;%
  content(as = &amp;quot;text&amp;quot;, encoding = &amp;quot;UTF-8&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;parsing-the-word-list&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Parsing the Word List&lt;/h1&gt;
&lt;p&gt;Next, I’m doing something messy that deserves some more explanation. I couldn’t figure out a good way to programmatically extract the entire word list by looking for the start and end points of the array, so instead, I scrolled through it in a text editor and manually identified the first and last words (&lt;code&gt;cigar&lt;/code&gt; and &lt;code&gt;shave&lt;/code&gt;, respectively). Then I told R to look for those particular words and extract everything between the two. It’s not ideal since rearranging the word list would completely break the rest of my script, so I’m open to any suggestions here!&lt;/p&gt;
&lt;p&gt;Anyway, that left me with a giant string of comma separated words. From there, I removed any escaped quotation marks and separated each word into its own element by splitting the string at each comma. Then I converted all of that to a data frame where each row is a word, renamed the column, and converted every word to upper case. I call this data frame &lt;code&gt;word_list&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;word_list = substr(
  wordle_script_text,
  # cigar is the first word
  str_locate(wordle_script_text, &amp;quot;cigar&amp;quot;)[,&amp;quot;start&amp;quot;],
  # shave is the last word
  str_locate(wordle_script_text, &amp;quot;shave&amp;quot;)[,&amp;quot;end&amp;quot;]) %&amp;gt;%
  str_remove_all(&amp;quot;\&amp;quot;&amp;quot;) %&amp;gt;%
  str_split(&amp;quot;,&amp;quot;) %&amp;gt;%
  data.frame() %&amp;gt;%
  select(word = 1) %&amp;gt;%
  mutate(word = toupper(word))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we have our word list!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;##    word
## 1 CIGAR
## 2 REBUT
## 3 SISSY
## 4 HUMPH
## 5 AWAKE&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;determining-overall-letter-frequency&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Determining Overall Letter Frequency&lt;/h1&gt;
&lt;p&gt;From there, my first idea was to get a frequency diagram of how often each letter appears. After all, intuitively, you wouldn’t expect letters like “X” to show up very often so it doesn’t make a lot of sense to play a word with “X” in it (unless you have a good reason). In the code below, I’m taking &lt;code&gt;word_list&lt;/code&gt; and converting it back to a character vector, splitting every single character into its own element, and converting to a data frame again. I’m calling this data frame &lt;code&gt;letter_list&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;At this point, I should clarify why I did &lt;code&gt;filter(row_number() != 1)&lt;/code&gt;. R added a &lt;code&gt;c()&lt;/code&gt; when I converted to a vector, which I don’t want to count towards the letter counts. This filter removes that extra &lt;code&gt;c&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Continuing with the rest of the code, I renamed the column, filtered for upper-case letters only, and summarized by letter counts in descending order.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;letter_list = word_list %&amp;gt;%
  as.character() %&amp;gt;%
  str_split(&amp;quot;&amp;quot;) %&amp;gt;%
  data.frame() %&amp;gt;%
  filter(row_number() != 1) %&amp;gt;%
  select(letter = 1) %&amp;gt;%
  filter(letter %in% LETTERS) %&amp;gt;%
  group_by(letter) %&amp;gt;%
  summarize(freq = n()) %&amp;gt;%
  arrange(desc(freq))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now we have our frequency by letter!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## # A tibble: 5 × 2
##   letter  freq
##   &amp;lt;chr&amp;gt;  &amp;lt;int&amp;gt;
## 1 E       1230
## 2 A        975
## 3 R        897
## 4 O        753
## 5 T        729&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But this isn’t very easy to read. Let’s throw it into a plot. A few callouts here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;By default, ggplot sorts the x axis in alphabetical order. &lt;code&gt;reorder&lt;/code&gt; forces ggplot to put the most frequent observations first.&lt;/li&gt;
&lt;li&gt;I used &lt;code&gt;stat = &#34;identity&#34;&lt;/code&gt; since we already summarized &lt;code&gt;letter_list&lt;/code&gt; in the previous section.&lt;/li&gt;
&lt;li&gt;I used &lt;code&gt;expand = c(0,0)&lt;/code&gt; to make the bars stretch all the way to the axis.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot(letter_list, aes(x = reorder(letter, (-freq)), y = freq)) +
  geom_bar(fill = &amp;quot;lightblue&amp;quot;,
           stat = &amp;quot;identity&amp;quot;) +
  geom_text(aes(x = reorder(letter, (-freq)),
                y = freq,
                label = comma(freq, accuracy = 1),
                vjust = 1),
            size = 2) +
  scale_y_continuous(labels = comma,
                     expand = c(0,0)) +
  theme_clean() +
  xlab(&amp;quot;Letter&amp;quot;) +
  ylab(&amp;quot;Frequency&amp;quot;) +
  labs(caption = &amp;quot;Generated by Arthur Holtz\nlinkedin.com/in/arthur-holtz/&amp;quot;) +
  ggtitle(&amp;quot;Letter Frequency in Wordle&amp;#39;s Official Word List&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2022/02/21/wordle-data-analysis/index_files/figure-html/unnamed-chunk-7-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Much better! Looking at this plot, my naive strategy is to open with words containing letters on the left side of the plot. They’re much more likely to show up – but even if they don’t, knowing that is also valuable information. So maybe something like “TEARS” or “IRATE” (my wife’s favorite) is a good starter. One interesting thing to note is that this &lt;strong&gt;doesn’t&lt;/strong&gt; match the &lt;a href=&#34;https://en.wikipedia.org/wiki/Letter_frequency&#34;&gt;overall letter frequency in English&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;determining-letter-frequency-for-each-position&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Determining Letter Frequency for Each Position&lt;/h1&gt;
&lt;p&gt;That’s all good to know, but I want more. Where do we go next? I got to thinking it would be helpful to know which letters are most likely to appear &lt;em&gt;where&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;To that end, I took &lt;code&gt;word_list&lt;/code&gt; and split each letter into its own column. R added an empty column when I tried to do this, so I had to add an extra column (&lt;code&gt;into = as.character(1:6)&lt;/code&gt;) and then remove the empty one and rename the others (the &lt;code&gt;select&lt;/code&gt;). Ugh, whatever. I called this data frame &lt;code&gt;ordered_letter_list&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ordered_letter_list = word_list %&amp;gt;%
  separate(word,
           sep = &amp;quot;&amp;quot;,
           into = as.character(1:6)) %&amp;gt;%
  select(-1,
         &amp;quot;l_1&amp;quot; = 2,
         &amp;quot;l_2&amp;quot; = 3,
         &amp;quot;l_3&amp;quot; = 4,
         &amp;quot;l_4&amp;quot; = 5,
         &amp;quot;l_5&amp;quot; = 6)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we have a set of data that looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;##   l_1 l_2 l_3 l_4 l_5
## 1   C   I   G   A   R
## 2   R   E   B   U   T
## 3   S   I   S   S   Y
## 4   H   U   M   P   H
## 5   A   W   A   K   E&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I wanted to plot each of these letter positions on its own chart, so I first created a function called &lt;code&gt;build_df&lt;/code&gt; that we can call in a &lt;code&gt;for&lt;/code&gt; loop that only takes one column at a time and summarizes it with the most to least common letters.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;build_df = function(df, col_name) {
  new_df = df %&amp;gt;%
    group_by(letter = eval(sym(col_name))) %&amp;gt;%
    summarize(freq = n()) %&amp;gt;%
    arrange(desc(freq))

  return(new_df)
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we plug this function into a &lt;code&gt;for&lt;/code&gt; loop to generate a plot for each letter position. Compared to the single plot before, there are some new things that are worth explaining:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I create an object called &lt;code&gt;letter_#&lt;/code&gt; and I set its value to be &lt;code&gt;ordered_letter_list&lt;/code&gt;, but only including the letter number in question.&lt;/li&gt;
&lt;li&gt;Since we’re inside a &lt;code&gt;for&lt;/code&gt; loop, ggplot won’t normally display plots. I wrap everything in &lt;code&gt;print&lt;/code&gt; to make sure we can see the plots.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;for (i in 1:5) {
  this_df = paste0(&amp;quot;letter_&amp;quot;, i)
  assign(this_df, build_df(ordered_letter_list, paste0(&amp;quot;l_&amp;quot;, i)))

  title = paste0(&amp;quot;Letter # &amp;quot;, i, &amp;quot; Frequency in Wordle&amp;#39;s Official Word List&amp;quot;)

  print(ggplot(eval(sym(this_df)), aes(x = reorder(letter, (-freq)), y = freq)) +
    geom_bar(fill = &amp;quot;lightblue&amp;quot;,
             stat = &amp;quot;identity&amp;quot;) +
    geom_text(aes(x = reorder(letter, (-freq)),
                  y = freq,
                  label = comma(freq, accuracy = 1),
                  vjust = 1),
              size = 2) +
    scale_y_continuous(labels = comma,
                       expand = c(0,0)) +
    theme_clean() +
    xlab(&amp;quot;Letter&amp;quot;) +
    ylab(&amp;quot;Frequency&amp;quot;) +
    labs(caption = &amp;quot;Generated by Arthur Holtz\nlinkedin.com/in/arthur-holtz/&amp;quot;) +
    ggtitle(title))
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2022/02/21/wordle-data-analysis/index_files/figure-html/unnamed-chunk-11-1.png&#34; width=&#34;672&#34; /&gt;&lt;img src=&#34;/2022/02/21/wordle-data-analysis/index_files/figure-html/unnamed-chunk-11-2.png&#34; width=&#34;672&#34; /&gt;&lt;img src=&#34;/2022/02/21/wordle-data-analysis/index_files/figure-html/unnamed-chunk-11-3.png&#34; width=&#34;672&#34; /&gt;&lt;img src=&#34;/2022/02/21/wordle-data-analysis/index_files/figure-html/unnamed-chunk-11-4.png&#34; width=&#34;672&#34; /&gt;&lt;img src=&#34;/2022/02/21/wordle-data-analysis/index_files/figure-html/unnamed-chunk-11-5.png&#34; width=&#34;672&#34; /&gt;
With these 5 additional charts in my arsenal, now I know not only which letters are most common in general, but also &lt;em&gt;where&lt;/em&gt; they are most likely to appear. One thing I was really surprised to find was just how uncommon “S” is as the 5th letter — only 36 out of 2,309 words! My best guess is the creators deliberately removed a number of plural words so there wouldn’t be so many words ending in “S.” It’s also neat how the 5 most frequent letters for the 3rd position are the vowels.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;brute-forcing-words-with-the-best-score&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Brute Forcing Words with the Best “Score”&lt;/h1&gt;
&lt;p&gt;After discussing the initial analysis above with my dad, we came up with another idea: What if we took every word and bumped it up against every other word in Wordle’s list, and scored the guesses based on how much information they reveal on average?&lt;/p&gt;
&lt;p&gt;I created a data frame called &lt;code&gt;ordered_letter_list_rev&lt;/code&gt; that’s mostly the same as &lt;code&gt;ordered_letter_list&lt;/code&gt;, except I only took the first 50 words (I’ll explain why later) and I kept the full word as the first column.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ordered_letter_list_rev = substr(
  wordle_script_text,
  str_locate(wordle_script_text, &amp;quot;cigar&amp;quot;)[,&amp;quot;start&amp;quot;],
  str_locate(wordle_script_text, &amp;quot;shave&amp;quot;)[,&amp;quot;end&amp;quot;]) %&amp;gt;%
  str_remove_all(&amp;quot;\&amp;quot;&amp;quot;) %&amp;gt;%
  str_split(&amp;quot;,&amp;quot;) %&amp;gt;%
  data.frame() %&amp;gt;%
  select(word = 1) %&amp;gt;%
  mutate(word = toupper(word)) %&amp;gt;%
  head(50) %&amp;gt;%
  separate(word,
           sep = &amp;quot;&amp;quot;,
           into = as.character(1:6),
           remove = FALSE) %&amp;gt;%
  select(-2,
         &amp;quot;l_1&amp;quot; = 3,
         &amp;quot;l_2&amp;quot; = 4,
         &amp;quot;l_3&amp;quot; = 5,
         &amp;quot;l_4&amp;quot; = 6,
         &amp;quot;l_5&amp;quot; = 7)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is what it looks like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;##    word l_1 l_2 l_3 l_4 l_5
## 1 CIGAR   C   I   G   A   R
## 2 REBUT   R   E   B   U   T
## 3 SISSY   S   I   S   S   Y
## 4 HUMPH   H   U   M   P   H
## 5 AWAKE   A   W   A   K   E&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, I created a data frame called &lt;code&gt;cross_joined&lt;/code&gt; where I joined &lt;code&gt;ordered_letter_list_rev&lt;/code&gt; to itself without any matching criteria. This is why I did &lt;code&gt;head(50)&lt;/code&gt; in the previous section — the resulting data frame will square the row count of the original data frame, and I wanted to start with a reasonable-sized subset. If you have access to cloud computing resources, the sheer amount of data is less of a concern, but I’m running this on a personal computer, so bear with me.&lt;/p&gt;
&lt;p&gt;Since this self-join would leave us with duplicate column names, I used &lt;code&gt;suffixes = c(&#34;_guess&#34;,&#34;_target&#34;)&lt;/code&gt; in the &lt;code&gt;merge&lt;/code&gt; function to distinguish the guesses from the target words. I also &lt;code&gt;filter&lt;/code&gt;ed out any rows where the guess is the same as the target since these cases don’t give us any useful information.&lt;/p&gt;
&lt;p&gt;Next came the scoring. My (somewhat arbitrary) idea was to give 3 points for getting the right letter in the right place, 1 point for the right letter in the wrong place, and 0 points for wrong letters. I know I did this part extremely inefficiently since there’s a lot of copy/pasted code. I tried searching Stack Overflow for how to do this properly but eventually realized I had spent more time searching than I would have spent using good ol’ copy/paste in the first place. Again, if you know a better way, I’m wide open to suggestions!&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;cross_joined = merge(ordered_letter_list_rev,
                     ordered_letter_list_rev,
                     by = NULL,
                     suffixes = c(&amp;quot;_guess&amp;quot;,&amp;quot;_target&amp;quot;)) %&amp;gt;%
  filter(word_guess != word_target) %&amp;gt;%
  mutate(
    l_1_score = case_when(
      l_1_guess == l_1_target ~ 3,
      l_1_guess == l_2_target ~ 1,
      l_1_guess == l_3_target ~ 1,
      l_1_guess == l_4_target ~ 1,
      l_1_guess == l_5_target ~ 1,
      TRUE ~ 0),
    l_2_score = case_when(
      l_2_guess == l_2_target ~ 3,
      l_2_guess == l_1_target ~ 1,
      l_2_guess == l_3_target ~ 1,
      l_2_guess == l_4_target ~ 1,
      l_2_guess == l_5_target ~ 1,
      TRUE ~ 0),
    l_3_score = case_when(
      l_3_guess == l_3_target ~ 3,
      l_3_guess == l_1_target ~ 1,
      l_3_guess == l_2_target ~ 1,
      l_3_guess == l_4_target ~ 1,
      l_3_guess == l_5_target ~ 1,
      TRUE ~ 0),
    l_4_score = case_when(
      l_4_guess == l_4_target ~ 3,
      l_4_guess == l_1_target ~ 1,
      l_4_guess == l_2_target ~ 1,
      l_4_guess == l_3_target ~ 1,
      l_4_guess == l_5_target ~ 1,
      TRUE ~ 0),
    l_5_score = case_when(
      l_5_guess == l_5_target ~ 3,
      l_5_guess == l_1_target ~ 1,
      l_5_guess == l_2_target ~ 1,
      l_5_guess == l_3_target ~ 1,
      l_5_guess == l_4_target ~ 1,
      TRUE ~ 0),
    total_score = l_1_score + l_2_score + l_3_score + l_4_score + l_5_score) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This gave me a data frame like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;##   word_guess l_1_guess l_2_guess l_3_guess l_4_guess l_5_guess word_target
## 1      REBUT         R         E         B         U         T       CIGAR
## 2      SISSY         S         I         S         S         Y       CIGAR
## 3      HUMPH         H         U         M         P         H       CIGAR
## 4      AWAKE         A         W         A         K         E       CIGAR
## 5      BLUSH         B         L         U         S         H       CIGAR
##   l_1_target l_2_target l_3_target l_4_target l_5_target l_1_score l_2_score
## 1          C          I          G          A          R         1         0
## 2          C          I          G          A          R         0         3
## 3          C          I          G          A          R         0         0
## 4          C          I          G          A          R         1         0
## 5          C          I          G          A          R         0         0
##   l_3_score l_4_score l_5_score total_score
## 1         0         0         0           1
## 2         0         0         0           3
## 3         0         0         0           0
## 4         1         0         0           2
## 5         0         0         0           0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While exploring the data here, I noticed something strange. To illustrate, let’s take a look at the score breakdown for guessing &lt;code&gt;MARRY&lt;/code&gt; when the target word is &lt;code&gt;MAJOR&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;##   l_1_score l_2_score l_3_score l_4_score l_5_score total_score
## 1         3         3         1         1         0           8&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice letters 3 and 4 (both &lt;code&gt;R&lt;/code&gt;s) are getting 1 point each. That’s not right! There’s only one &lt;code&gt;R&lt;/code&gt; in &lt;code&gt;MAJOR&lt;/code&gt; so this guess should really only get 7 points. There were a number of other cases like this (&lt;code&gt;ERASE&lt;/code&gt; was a major offender because it has 2 &lt;code&gt;E&lt;/code&gt;s, which you might recall was the most common letter in Wordle overall). The scores for guesses like these are inflated, so I wouldn’t trust this scoring logic.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;conclusion&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;This is where I got stuck. It must be possible to only give points for repeat letters once if there is only one such letter in the answer — but how? I can’t figure it out without making a super-complicated &lt;code&gt;case_when&lt;/code&gt; statement. If someone has a brilliant idea, I’d be thrilled to expand upon this analysis in a future update.&lt;/p&gt;
&lt;p&gt;And where would you go next? Assuming I can solve the scoring problem, I’d also like to use the entire &lt;code&gt;Oa&lt;/code&gt; word list as my guessing pool so I can find the most useful guesses, even if they won’t necessarily be the target word.&lt;/p&gt;
&lt;p&gt;I hope you’ve enjoyed walking through Wordle’s code and word list with me! Even though I couldn’t complete all the analysis I originally set out to do, I’m just hoping the overall and by-location frequency analysis give me enough of an edge to do better than my wife!&lt;/p&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2022/02/21/wordle-data-analysis/&#39;;&lt;/script&gt;
      </description>
    </item>
    
  </channel>
</rss>
