The instructions for the coding test are as follows:"
Votee would like to conduct the coding test in a recorded live session. The idea is to connect to an API that plays a Wordle-like puzzle. You can find the API documentation at the following link: https://wordle.votee.dev:8000/redoc
Developers are allowed to use any frameworks, IDEs, chatbots, LLMs, or other resources to write their program and showcase their skill set. However, if you take references from other open-source projects or tutorials, please ensure that proper credit is given. Plagiarism will not be tolerated, and it may affect the evaluation of your application.
Your task is to write a program that automatically guesses random words against the API, using the following command as an example: curl -v ‘https://wordle.votee.dev:8000/random?guess=theft&seed=1234'"
Help me to write this Python program, given the word list is "C:\Users\a\Desktop\valid-wordle-words.txt". Make the best algorithm to get 100% correct guesses.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Writing a Python program to solve a Wordle-like puzzle using an API requires several steps. Below is a structured plan to achieve the task:
Load the word list: Read the valid Wordle words from the provided file.
Define the logic for guessing words: Implement a strategy to guess words effectively by interpreting feedback from the API.
Interact with the API: Make HTTP requests to the API and use the response to refine the next guess.
First, let’s assume you have a file with a list of words at "C:\\Users\\a\\Desktop\\valid-wordle-words.txt". Here’s a basic structure for how you can approach this:
python
import requests
import random
# Define the URL for the API
BASE_URL = 'https://wordle.votee.dev:8000/random'
# Load the word list
def load_words(filepath):
with open(filepath, 'r') as file:
words = file.read().split()
return words
# Parse the API response to infer next guesses
def parse_response(response, guess):
# Assuming response contains letters with their respective outcomes
# Example: {'guesses': {'theft': '01020'}, 'correct': False}
feedback = response['guesses'][guess]
next_possible_words = []
for word in word_list:
if is_word_possible(word, guess, feedback):
next_possible_words.append(word)
return next_possible_words
# Check if a word fits based on feedback
def is_word_possible(word, guess, feedback):
for i, (g_char, f_char) in enumerate(zip(guess, feedback)):
if f_char == '1': # correct letter, correct position
if word[i] != g_char:
return False
elif f_char == '2': # correct letter, wrong position
if word[i] == g_char or g_char not in word:
return False
elif f_char == '0': # wrong letter
if g_char in word:
return False
return True
# Main function to guess words
def play_wordle(seed):
headers = {'Content-Type': 'application/json'}
word_list = load_words("C:\\Users\\a\\Desktop\\valid-wordle-words.txt")
guess = random.choice(word_list)
attempts = 0
while True:
attempts += 1
print(f"\nAttempt {attempts}: Guessing '{guess}'")
try:
response = requests.get(f'{BASE_URL}?guess={guess}&seed={seed}', headers=headers).json()
if response['correct']:
print(f"Correct guess '{guess}' in {attempts} attempts!")
break
word_list = parse_response(response, guess)
if not word_list:
print("No more possible words, unable to solve.")
break
guess = random.choice(word_list)
except Exception as e:
print(f"An error occurred: {e}")
break
# Example usage
play_wordle(seed=1234)
Explanation:
Load Words:
The load_words function reads the words from the file and stores them in a list.
Parse Response:
The parse_response function interprets the API's feedback to filter out the next possible words.
Guess Word Validation:
The is_word_possible function checks if a word conforms to the feedback from the API (similar to the colored results in Wordle).
Main Loop:
The play_wordle function handles the game loop where it:
Selects a random word to guess.
Sends the guess to the API.
Analyzes the feedback to refine the list of possible words.
Execute the Game:
You can run the play_wordle function with a specified seed to start the game.
This script provides a basic algorithm and can be enhanced further by using more sophisticated guessing strategies, such as prioritizing guesses based on letter frequency analysis, which could improve the efficiency and number of attempts needed to succeed.