Settings

Theme

Reverse engineering Wordle

reichel.dev

63 points by rreichel03 4 years ago · 66 comments

Reader

GycDH6mb 4 years ago

> It seems like many of the variables are given names that are not descriptive at all to make it a bit more difficult to read.

The code is just minimized for prod..

The article as written makes it sound like the developer(s) intentionally wrote their code cryptically, whereas minimization for deployment is fairly standard practice

  • tyingq 4 years ago

    How common is it to have your minifier change symbol/variable names to short ones?

    • deergomoo 4 years ago

      Pretty much all of them do it. You can’t minify keywords or literals, so that just leaves whitespace, which would be barely any minification at all.

      • tyingq 4 years ago

        Jsmin cited a typical 50% reduction without touching symbols, though perhaps that's an average that included removing comments.

    • joek1301 4 years ago

      I just popped open DevTools on an SPA I made using create-react-app with default settings. Sure enough the minified production JavaScript uses shortened variable names. This is default configuration for Webpack, which is pretty widely used throughout (and outside) the React ecosystem.

      Interestingly you can still view the unminified source, since create-react-app generates source maps by default.

    • VoidWhisperer 4 years ago

      It is pretty common. The goal of the minifier is to reduce the size of the file, so taking the function names, variable names, etc and making them as short as possible works towardd that goal

    • spdustin 4 years ago

      Closure Compiler (for JavaScript) does it. With the SIMPLE_OPTIMIZATIONS [0] flag, it will rename parameters for—and variables local to—functions to save space.

      [0]: https://developers.google.com/closure/compiler/docs/compilat...

    • kbelder 4 years ago

      I've seen some minifiers that can restructure your code... replace if{} with a ternary ?: operator or use boolean shortcutting to replace the whole conditional with a ||, and so on. It's supposed to never do anything that actually affects the logic, but that sort of stuff scares me.

    • nilsbunger 4 years ago

      Very common

    • 0xfeba 4 years ago

      That's literally what they are for.

      • tyingq 4 years ago

        For some context, it didn't used to be terribly common. There's a fair amount of minifying that you can do without touching symbol names, though obviously it doesn't help as much as shortening them. The old jsmin cited about 50% reduction, and it didn't touch any variable or class names.

    • k3liutZu 4 years ago

      It's actually pretty standard

  • jer0me 4 years ago

    If they really wanted to hide it, there are some nasty obfuscators for JavaScript: https://obfuscator.io/

returningfory2 4 years ago

A word of warning for anyone inspecting the Wordle source code: the answers for each day are stored in a list ordered by day. If you search for today's answer, the next word in the list will be tomorrow's answer, etc. Be careful not to ruin the fun by seeing tomorrow's answer in advance!

  • 1-more 4 years ago

    And def don't run `(new wordle.bundle.GameApp()).solution` in your browser console; you'll only be cheating yourself.

  • netule 4 years ago

    You can also see the solution and various other points of pertinent data stored as a JSON string in your localStorage without having to dive into code.

sgmoore 4 years ago

> var Ha = new Date(2021,5,19,0,0,0,0); > My assumption is that this is the launch date for Wordle

But not 19th of May 2021, but 20th of June 2021

Every time I look as JavaScript, I find a new reason to hate it.

nilsbunger 4 years ago

I figured that was possible; from the UX it was pretty clear it’s all client side.

What I would find cool is derivation of the best strategy at any time. Just like blackjack, there should be a “best” move at all times , and it would be cool to measure yourself against that

  • scubbo 4 years ago

    I haven't implemented the best strategy at _all_ times, but this blog post[0] proposes a strategy (pick the word that minimizes the expected-size of the resultant set of possible answers). I made a User Script[1] that tells you how many words remain after each guess - it shouldn't be too hard to expand that to tell you a) what the expected answer-set-size was with your answer, and b) how that compares with the "best" answer.

    [0] https://blog.scubbo.org/posts/cheating-at-word-games/ [1] https://blog.scubbo.org/posts/cheating-at-word-games-part-3/

  • greenshackle2 4 years ago

    I made one, not the optimal strategy though, I simply minimized the expected number of possible solutions for the next step. I repurposed my Mastermind solver since it's basically the same game. Just like Mastermind, minimax is probably better than what I did, but it does solve every Wordle in at most 5 guesses, on average 3.4 guesses.

    https://github.com/jbchouinard/untitled-word-game

    https://en.wikipedia.org/wiki/Mastermind_(board_game)#Best_s...

    • pbhjpbhj 4 years ago

      >it's basically the same game //

      Surely it differs from Mastermind (which I might not be remembering well as I didn't like it) in that the answers must be words in the game's dictionary rather than arbitrary colour codes? That seems to change tactics considerably.

      • greenshackle2 4 years ago

        I agree it changes the experience of playing the game for a human quite a bit, and you'll use different tactics, but for the kind of solver I made it doesn't change much - I had to change very little code to make it work.

        From the perspective of the solver it just means the starting set of potential solutions is every word in the dictionary, instead of every permutation, but it doesn't really make much of a structural difference. Either way a solver can just brute-force its way through every potential solution since there aren't that many.

        The other difference is that Mastermind tells you only how many of the pegs are correct, but not which ones. Wordle tells you which ones. That is easier, but it's counterbalanced by Wordle having a larger solution space. There's only 1296 possible solutions for classic Mastermind (4 pegs, 6 colors).

    • eutectic 4 years ago

      I think using the expected logarithm of the number of solutions (entropy) makes more sense from an information theory perspective. I wonder if it works better in practice.

  • matthewfcarlson 4 years ago

    I think there’s been a few of those on hacker news. Let me dig one up

    • Reventlov 4 years ago

      There is this one (from myself) : https://remy.grunblatt.org/static/wordle/wordle.svg (dynamic version: https://remy.grunblatt.org/static/wordle/).

      It's not optimal at all, but works for every wordle word; it's built by finding the word (guess) that minimizes the maximum size of the possible words (to guess), a bit like Knuth Algorithm for Mastermind.

      For an optimal strategy, a backtracking solution with pruning / maybe a branch and bound approach would work, but I didn't manage to implement a fast enough implementation for my small 8 threads CPU.

qrohlf 4 years ago

This is an unusual thing to find myself typing in a HN thread, but this could use a spoiler tag, as I did not expect to have tomorrow’s challenge ruined for me by a technical blog post.

  • magneticnorth 4 years ago

    I'm not easily finding the publication date, but for me the article says tomorrow's word is "query", which was actually the word a couple days ago. If that's what you see, too, then I think it's safe.

  • heyheyhey 4 years ago

    I really wish Wordle would release the daily puzzle where everyone can do it at the same time.

dzdt 4 years ago

I just hope the wordle developers manage to cash in on their going-viral jackpot without losing it to copycats or spoiling the experience for players.

  • giarc 4 years ago

    I believe the developer was interviewed and said he/she has no plans to change the game to make money. If you go to just https://www.powerlanguage.co.uk/ (maker of the game) you can see he made other games on Reddit (The Button and Place) and is listed as an artist, product manager, and engineer. I suspect the attention the game has received has resulted in many head hunters reaching out. Think of Wordle as a loss leader for his career.

    • dTal 4 years ago

      Wow, they made The Button as well? That's amazing. They have considerable talent for going viral, it seems.

antoniomika 4 years ago

I made a little change that allowed setting the day's puzzle based on puzzle ID number via a query parameter so you could play previous day's puzzles. Here's the gist with relevant code block if anyone's curious: https://gist.github.com/antoniomika/5ec4741d309cc829a5bc26a5...

primeradical 4 years ago

I rebuilt Wordle from scratch using the same word list. There are actually two word lists, one from which they select the answer, and another from which they validate real words. They are just arrays of strings hardcoded in the JS bundle.

When you submit a guess, it checks to see if your guess is in either array (or at least that's how I implemented it). And just does some relatively simple string comparison.

Your progress is just stored in local storage. You can blow your data away by deleting it via dev tools.

My version just lets you try again by refreshing, I'm not storing any data.

The viral factor of the original Wordle, IMO, is the share function and the little emoji grid it generates.

https://alexmj212.dev/word-guess/

Source: https://github.com/alexmj212/word-guess

  • tradertef 4 years ago

    >> The viral factor of the original Wordle, IMO, is the share function and the little emoji grid it generates.

    Yes, that is really genius. That's what made me to wonder what this game was about.

  • travisporter 4 years ago

    Nice port! However it's not letting me re-use a guessed letter, which makes it way harder to guess the answer

ericmcer 4 years ago

Wordle is easy to cheat at. All the validation and past scores are client side, the code and concept is simple, but why would you cheat?

No offense to the author but I am kinda confused why someone would even open the inspector and be like: "how is this being done?!"

  • _moof 4 years ago

    > I am kinda confused why someone would even open the inspector and be like: "how is this being done?!"

    Kids these days.

    When I was young I would disassemble anything with a circuit board. The Nintendo, the garage door opener... parents drew the line at the VCR though.

manceraio 4 years ago

This website is crashing Chrome on my Xiaomi :/

  • gizajob 4 years ago

    Came here just to post this too - My Motorola is now stuck in an endless loop of chrome crashes because it keeps trying to reload this blog and gets stuck every time, even trying to navigate away crashes chrome. Robert - next time you attack the source of a website, make sure the source of your own website runs properly first.

  • palijer 4 years ago

    Yeah! Came here to say the same thing, Chrome on a One Plus Six.

classichasclass 4 years ago

This was good while my wife and I were in the same time zone: we compared guesses and how we got there. Now that she's a day ahead, we can't do that right now (we found this out when she accidentally did a spoiler).

  • kumarharsh 4 years ago

    One thing I do while playing with people half a world away is to send just the final pattern (Share button copies that to the clipboard). Once both parties have sent their answers, you can share the screenshots :-)

  • ec109685 4 years ago

    I’ve temporarily changed my time zone to play a bit earlier a few times.

ath3nd 4 years ago

I actually did the same thing a week or so ago, but in a more readable format: https://gist.github.com/lc-nyovchev/c42f09a48364665da2634259...

And https://ath3nd.wordpress.com/2022/01/11/about-wordle/

The idea with the game is to have fun, not to make it impenetrable for techies (in which case a backend would have been nice)

bluesmoon 4 years ago

Fun times. I remember back in the year 2000, during the dot com craze, there was a company in India that built a clone of "Who wants to be a millionaire". It was in beta and there was no real cash or prize involved.

They had all the answers stored in the source code. I wrote up a quick perl script to play the game and unfortunately left it running overnight, and in the morning there were complaints from other players asking how I'd reached the top rank so quickly.

anyfactor 4 years ago

I guess I wasn't the only person who tried to reverse engineer wordle because they were stuck on the final try.

I thought I would do a programmatic soltion because that was the only win I will be able to get. I did find it interesting that they had all the 5 letter words in the frontend logic.

thavalai 4 years ago

I liked this deconstruction of Wordle a lot: https://bert.org/2021/11/24/the-best-starting-word-in-wordle...

lilac1 4 years ago

I'm not sure why you'd want to reverse engineer something that isn't trying to hide anything. Just enjoy playing it!

I've seen quite a few blogs/tools all trying to surf the wave of Wordle.

gizajob 4 years ago

ROBERT! Your website crashes Chrome on Android. Please fix before reverse-engineering anything else.

saneshark 4 years ago

how long before this is ported to IOS and becomes the #1 grossing game? I'm thinking ketchapp is already on it.

t1ber1us 4 years ago

This is brilliant

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection