Giter VIP home page Giter VIP logo

pyvo-2022-03-copylot's Introduction

Wordle solver in Python

Written mostly by GitHub Copilot.

The rest here is actually Copilot babble, trying to write a readme.

A demonstration of a project written by Copilot. At least in part, this project is a wordle solver. When Copilot is not programming, he is playing a game called "Wordle". Let's try if he can solve it.

This code implements a 'good' strategy, not an optimal one. For optimal strategies, check Jonathan Olson's page.

Slides for the talk

Google Slides

How to use

Python 3.10

import wordle
import solver

solver.RandomSolver(wordle.Game(word_index=1)).solve(verbose=True)

# solve all challenges, calculate percentage solved
run = [
  solver.RandomSolver(wordle.Game(word_index=i)).solve(max_rounds=6)
  for i in range(len(wordle.words.challenges))
]
sum(1 for rounds, _ in run if rounds < 6) / len(wordle.words.challenges)

# 54% of challenges solved

# EntropySolver is used in similar manner
solver.EntropySolver(wordle.Game(word_index=1)).solve(verbose=True, max_rounds=6)
run = [
  solver.EntropySolver(wordle.Game(word_index=i)).solve(max_rounds=6)
  for i in range(len(wordle.words.challenges))
]
sum(1 for rounds, _ in run if rounds < 6) / len(wordle.words.challenges)
# 100% of challenges solved

import statistics
statistics.mean(r+1 for r, _ in run)
# 3.639

# a histogram
[(k,  cc[k]) for k in sorted(cc.keys())]
[(1, 22), (2, 898), (3, 1284), (4, 102), (5, 3)]

# the difficult words
[(i, w) for i, (r, w) in enumerate(run) if r == 5]
[(145, 'baker'), (2219, 'wafer'), (2229, 'waver')]

Pre-computed first round

At start there are no clues. soare is the word that is picked every time by the EntropySolver. We can also pre-compute the candidates based on pattern after the first guess and the best guess for those candidates.

import wordle, solver
soare_patterns = set(wordle.eval_guess(c, 'soare') for c in wordle.words.challenges)
soare_cands = {pat:solver.filter(wordle.words.challenges, 'soare', pat) for pat in soare_patterns}
soare_guess = {pat:max(solver.entropies(wordle.words.all, cands), key=lambda x: x[0]) for pat, cands in soare_cands.items()}

with open('soare.p', 'wb') as fo:
    pickle.dump(((0, 'soare'), soare_cands, soare_guess), fo, protocol=pickle.HIGHEST_PROTOCOL)

pyvo-2022-03-copylot's People

Contributors

libor-m avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.