initial commit

current
Síle Ekaterin Liszka 2022-09-26 06:32:47 -07:00
commit 9c70df249b
6 changed files with 12725 additions and 0 deletions

32
.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app

29
LICENSE Normal file
View File

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2022, Síle Ekaterin Liszka
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

12
README.textile Normal file
View File

@ -0,0 +1,12 @@
h1. Candid Words
This is a basic algorithm for generating a list of Wordle candidates based on yellow and green tiles.
h2. Building
You will need a C++11 compiler, for instance @g++ -std=c++11@. If you want to use a specific word list, save it as a plaintext file at 'words.txt' and run @convert.py@ before compiling the program.
h3. Copyright
The code is made available under BSD-3-Clause.

44
convert.py Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
#
# Copyright 2022 Síle Ekaterin Liszka
#
1 2 3 4 5 6 7
123456789012345678901234567890123456789012345678901234567890123456789012
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
words = []
with open('words.txt', mode='r') as f:
data = f.read()
words = data.replace('\n', '').split(' ')
x = 0
with open('words.hh', mode='w+') as f:
f.write('static const std::vector<std::string> wordv {\n')
for word in words:
x += 1
f.write(f'\t"{word}",\n')
f.write('};\n')

127
wordle.cc Normal file
View File

@ -0,0 +1,127 @@
/*
* Copyright 2022 Síle Ekaterin Liszka
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include "words.hh"
void usage(char *);
int main(int argc, char **argv) {
if (argc != 4) {
usage(argv[0]);
return -1;
}
std::string yellow(argv[1]);
std::string green(argv[2]);
std::string guessed(argv[3]);
std::string invalid;
std::vector<std::string> candidates;
// Are these arguments acceptable?
for (std::string::size_type i = 0; i < yellow.length(); i++) {
if (!std::isalpha(yellow[i])){
std::cout << "invalid yellow " << yellow[i] << " at " << i << std::endl;
usage(argv[0]);
return -1;
}
}
for (std::string::size_type i = 0; i < green.length(); i++)
{
if (!std::isalpha(green[i]) && (green[i] != '?'))
{
std::cout << "invalid green: " << green[i] << std::endl;
usage(argv[0]);
return -1;
}
}
for (std::string::size_type i = 0; i < guessed.length(); i++)
{
if (!std::isalpha(guessed[i]))
{
std::cout << "invalid guessed: " << yellow[i] << std::endl;
usage(argv[0]);
return -1;
}
}
// What letters aren't valid?
for (std::string::size_type i = 0; i < guessed.length(); i++) {
if (yellow.find(guessed[i]) == std::string::npos) {
invalid.append(1, guessed[i]);
}
}
for (std::vector<std::string>::size_type i = 0; i < wordv.size(); i++) {
bool valid = false;
std::string word(wordv[i]);
for (int j = 0; j < 5; j++) {
if (invalid.find(word[j]) != std::string::npos) {
valid = false;
break;
}
if (green[j] == '?') {
continue;
}
if (word[j] == green[j]) {
valid = true;
} else {
valid = false;
break;
}
}
for (std::string::size_type j = 0; j < yellow.length(); j++) {
if (word.find(yellow[j]) == std::string::npos) {
valid = false;
break;
}
}
if (valid) {
candidates.push_back(word);
}
}
std::for_each(candidates.begin(), candidates.end(), [](std::string n) { std::cout << n << " "; });
std::cout << std::endl;
}
void usage(char *progname) {
std::cout << "Usage: " << progname << " <yellow> <green> <guessed>\n\n" <<
"<yellow> must be up to five letters which are contained in the word.\n" <<
"<green> must be either question marks or correctly-placed letters.\n" <<
"<guessed> is all of the letters guessed so far.\n";
}

12481
words.hh Normal file

File diff suppressed because it is too large Load Diff