This C++ program generates a 5x5 grid with 25 unique characters using words from a text file. It uses a combination of nested loops and set operations to find groups of five words where all letters are unique. The program calculates the score for each solution based on the letter ranks and outputs the solutions in a formatted manner.
The program is structured into several classes and functions:
The Word
class represents a word and contains the following members:
score
: The sum of letter ranks.letters
: An unordered set of integers representing the unique letters in the word.word
: The string representation of the word.
The Word
class provides methods to retrieve the letters, word, score, and set size. It also calculates the score based on a given character map.
The Solution
class represents a solution consisting of five words. It contains the following members:
solutionList
: An array ofWord
objects representing the five words.score
: The total score of the solution.
The Solution
class provides a method to format the solution as a string.
The program also includes several helper functions for set operations, formatting time, reading input files, searching for solutions, and writing results to storage.
To use the program, follow these steps:
- Compile the C++ program using a C++ compiler.
- Run the compiled program.
- The program will read a text file containing a list of five-letter words. You can specify the file path as a command-line argument.
- The program will generate unique character grids by finding groups of five words where all letters are unique.
- The program will output the solutions in a formatted manner.
- The solutions will be written to a file named "results.txt".
Here is an example of how to run the program:
$ ./unique_character_grid program_input.txt
This command will run the program using the input file "program_input.txt" to generate unique character grids. The solutions will be displayed on the console and written to the "results.txt" file.
The program requires the following C++ libraries:
<algorithm>
<array>
<chrono>
<fstream>
<iomanip>
<iostream>
<map>
<ostream>
<random>
<sstream>
<unordered_set>
<vector>
Feel free to explore the source code for more details and customization options.