Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:22:58+00:00 2026-06-01T04:22:58+00:00

I’m writing a console-environment Hangman game for my introductory programming class. The player chooses

  • 0

I’m writing a console-environment Hangman game for my introductory programming class. The player chooses the word length and number of guesses they would like. ‘Easy mode’ is simple enough… generate a random number to use as the list’s index and check that the chosen word is the right length. However, ‘hard mode’ requires the list to be refined as the game progresses, choosing the largest list of possibilities given the letters guessed.

I should note, we are not using the C# List class but instead, creating array-based structs:

    struct ListType
    {
        public type[] items;
        public int count;
    }

    //defined as:

    ListType myList = new ListType();
    myList.items = new type[max value];
    myList.count = 0;

Anyway, here’s an example of the way ‘hard mode’ should go:

Word List:
hole
airplane
lame
photos
cart
mole

(player chooses word length of 4)

Word List (refined):
hole
lame
cart
mole

(player guesses "l", then "e")

Word List (refined):
hole
mole

“Lame” is omitted because more words have the “…le…” pattern. The technique that makes sense to me (but isn’t working the way I’d like) is storing each word’s pattern to an array (ie: “mole” and “hole” = 0011, and “lame” = 1001), and counting up the duplicates to determine the larger list.

Is this the way I should be doing it? I’m new to programming and have just under a year’s worth of experience, so I guess answer as such.

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:22:59+00:00Added an answer on June 1, 2026 at 4:22 am

    There are a few ways of approaching this. A simple way would be to keep track of a list for all candidate words and calculate the amount of matching sequences for that word as well as log the best matching sequence. This way you can both sort on the best sequence and the amount of sequences when the best sequence alone is not a good enough measurement tool. I hope it becomes obvious how to modify this code in order to only sort on the best sequence.

    Firstly i setup a test case like:

    // mimic the scenario given by the QA
    string[] wordList = new string[] { "hole", "airplane", "lame", "photos", "cart", "mole" };
    int wordLength = 4;
    List<char> requiredCharacters = new List<char>{ 'l', 'e'};
    

    After which i filter the wordList and calculate the best matches which i finally group together to produce the desired result:

    // filter all words that dont match the required length
    var candidateWords = wordList.Where(x => x.Length == wordLength);
    
    // define a result set holding all the words and all their matches
    Dictionary<string, List<int>> refinedWordSet = new Dictionary<string, List<int>>();
    
    foreach (string word in candidateWords)
    {
        List<int> matches = new List<int>() { 0 };
    
        int currentMatchCount = 0;
        foreach (char character in word)
        {
            if (requiredCharacters.Contains(character))
            {
                currentMatchCount++;
            }
            else
            {
                // if there were previous matches
                if (currentMatchCount > 0)
                {
                    // save the current match
                    matches.Add(currentMatchCount);
                    currentMatchCount = 0;
                }
            }
        }
    
        // if there was a match at the end
        if (currentMatchCount > 0)
        {
            // save the last match
            matches.Add(currentMatchCount);
        }
    
        refinedWordSet.Add(word, matches);
    }   
    
    // sort by a combination of the total amount of matches as well as the highest match
    var goupedRefinedWords = from entry in refinedWordSet
                                group entry.Key by new { Max = entry.Value.Max(), Total = entry.Value.Sum() } into grouped
                                select grouped;
    
    foreach (var entry in goupedRefinedWords)
    {
        Console.WriteLine("Word list with best match: {0} and total match {1}: {2}", 
            entry.Key.Max,
            entry.Key.Total,
            entry.Aggregate("", (result, nextWord) => result += nextWord + ", "));
    }
    
    Console.ReadLine();
    

    Pay attention to the comments in the code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I am writing an app with both english and french support. The app requests
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.