Skip to main content
added 16 characters in body
Source Link
Alexey R.
  • 11.6k
  • 5
  • 20
  • 39

Here is the algorithm:

  1. For each question you should detect the total number of answers. Lets put it to variable numAnswers.
  2. Being on a particular question (let variable currQuestion hold the current Question number) you should take the value index which will be evaluated as: index = currQuestion % numAnswers (all indices start from 0)

Below is the example of how algorithm work:

#Qestion    totalAnswers    index
0           5               0
1           5               1
2           3               2
3           3               30
4           3               1
5           2               1 <-- **

** - the index will remain the same here. This is what you will probably have to rework in the algorithm. This happens because of variable number of answers for each question and will not be an issue if the number of answers will be constant. However I just give you a direction and it is up to you how to improve the approach.

Here is the algorithm:

  1. For each question you should detect the total number of answers. Lets put it to variable numAnswers.
  2. Being on a particular question (let variable currQuestion hold the current Question number) you should take the value index which will be evaluated as: index = currQuestion % numAnswers

Below is the example of how algorithm work:

#Qestion    totalAnswers    index
1           5               1
2           3               2
3           3               3
4           3               1
5           2               1 <-- **

** - the index will remain the same here. This is what you will probably have to rework in the algorithm. This happens because of variable number of answers for each question and will not be an issue if the number of answers will be constant. However I just give you a direction and it is up to you how to improve the approach.

Here is the algorithm:

  1. For each question you should detect the total number of answers. Lets put it to variable numAnswers.
  2. Being on a particular question (let variable currQuestion hold the current Question number) you should take the value index which will be evaluated as: index = currQuestion % numAnswers (all indices start from 0)

Below is the example of how algorithm work:

#Qestion    totalAnswers    index
0           5               0
1           5               1
2           3               2
3           3               0
4           3               1
5           2               1 <-- **

** - the index will remain the same here. This is what you will probably have to rework in the algorithm. This happens because of variable number of answers for each question and will not be an issue if the number of answers will be constant. However I just give you a direction and it is up to you how to improve the approach.

Source Link
Alexey R.
  • 11.6k
  • 5
  • 20
  • 39

Here is the algorithm:

  1. For each question you should detect the total number of answers. Lets put it to variable numAnswers.
  2. Being on a particular question (let variable currQuestion hold the current Question number) you should take the value index which will be evaluated as: index = currQuestion % numAnswers

Below is the example of how algorithm work:

#Qestion    totalAnswers    index
1           5               1
2           3               2
3           3               3
4           3               1
5           2               1 <-- **

** - the index will remain the same here. This is what you will probably have to rework in the algorithm. This happens because of variable number of answers for each question and will not be an issue if the number of answers will be constant. However I just give you a direction and it is up to you how to improve the approach.