I am creating a mathematic app for iOS that contain simple tasks for children.
My objective is: compare an user answer with a defined answer in the particular task.
For example: users have to answer on questions e.g. 10 + 6 = 16, 20 – 2 = 18 etc…
But also I have task that users must solve in few steps.
For example: Ben went 5 miles. In the next day he went 10 miles. To get home, he needs to walk 20 miles. Question is – how many miles does he needs to walk to get home?
So the solution is next:
- 5 + 10 = 15
- 20 – 15 = 5
Answer: 5 miles
Well, I have created all my tasks in the JSON format and now I can compare user answer and right answer based on the string. But now I have a little bit problem. For example if I compare full string thats means I don’t allow users move components. For example user can create next solution:
- 10 + 5 = 15 but also he can create another variant 5 + 10 = 15.
- 20 – 15 = 5
So, there are no problems if I will keep all anwers, because I will analyze all strings and it will be perfect. But I think this is bad solution to keep all answers in JSON (I mean all variant answers)
But, maybe it is only one solution. What do you think?
Ok so you don’t want to transfer too much Data via JSON format. I would suggest using brackets to ensure order of operations. Evaluate the answer to make sure it is the correct one. On the server, you could run a script that cuts the numbers out and put them into an array list of some sorts. Then check if all the numbers in the correct answer are in the numbers in the user submitted string. If you are only doing addition, then your fine but if you introduce new operations like division or modulo, you need to use brackets are evaluate each operation by expanding brackets. For example, you would have an answer like 10+(9+2). Evaluate 9+2 first and ensure that all the operations that are happening in the brackets are correct and then evaluate the answer in that set of brackets with the operations on the outside. Don’t do too many computations on the phone though.
Good luck.