Background
I have created an application that queries the user for facts, then allows them to set parts of these facts as fill in the blanks. One of the key ideas is the user will be able to create multiple facts, e.g. George Washington was a president of the USA
and Franklin D. Roosevelt was a president of the USA
, and be able to know both George Washington and Franklin D. Roosevelt are presidents.
The challange
The problem comes in situations where one of these is plural and the other is singular. It could also occur when one ends with a vowel (meaning you’d have to use an
instead of a
), and the other Then, while answering a multiple choice question to fill in that blank, the question might ask Stackoverflow is a website
and give the option, organization
. Is there any way to fix these issues other than using a/an, and what algorithms could be used to achieve the desired result.
2
Answers
you would want to create templates, with a list of possible answers
such as
before we start the code.
you will need to generate these
questions
array from thefacts
store each fact, and then group them together so that:
George Washington was a president of the USA
Franklin D. Roosevelt was a president of the USA
These are very similar, so use some logic to get the difference, as both share the string format of
__ was a president of the USA
with this data, you can now generate the
questions
array, and the code following will work. The generating from the facts might be tricky but its a great learning experience, good luck.Then just loop through each question, and check if the answer matches one of the possible answers. if so then just count that as
+1
else if not a match, go to the next question or just repeat the questionRegarding the
an/a
you would just have to check if the spot before or next to the__
starts with a vowel.Example Output: