#include <fstream>
#include <iostream>
#include <string>
int line_of(const std::string& string, std::ifstream& file)
{
std::string line;
for (int number = 0; ; ++number) {
std::getline(file, line);
if (line == string)
return number;
}
return -1;
}
void print_line(std::ifstream& file, int number)
{
std::string line;
for (int i = 0; i < number; ++i)
std::getline(file, line);
std::getline(file, line);
std::cout << line << std::endl;
}
int main()
{
while (true) {
std::ifstream questions("questions.txt"), answers("answers.txt");
std::string input;
std::cout << "Ask me a question: " << std::flush;
std::getline(std::cin, input);
int number = line_of(input, questions);
print_line(answers, number);
}
return 0;
}
The contents of the files "questions.txt" (every possible question) and "answers.txt" (every possible answer) are left as an exercise to the reader.
I have skipped out error checking. If you get a wrong answer or an infinite loop it just means that your questions.txt or answers.txt are insufficient. The program is 100% correct.
If any question isn't in the questions.txt file or any answer isn't in the answers.txt file, or the answer is wrong, then the files are wrong, the program is still 100% correct. It can always pass the Turing test given correct data.
It is my view that this is a failure of the data, not a failure of the program.
The program is correct in the sense that it correctly implements this informal specification:
pre: input contains answers to every possible Turing test
post: output contains the answers for the Turing test in the input
It's incorrect in the sense that the specification doesn't properly describe the problem of passing every possible Turing test, so no program that implements it will pass every possible Turing test.
@Catfish3
Okay, let me revise that statement to this: The program never fails on its own merits, it only fails as a result of erroneous input. But the same can be said of any program for which there exists a distinction between valid and invalid input - garbage in, garbage out.
@helios
It would if the data were correct. I know you say that the data can't ever be correct, but that's not a failure of the program, that's a failure of god to provide a universe where a set of all possible data can exist.
Like I said, the program is correct. The specification is not.
If I asked you to specify and write a program that tests if a number is prime and you do this: