Search Unity

Remove duplication in a list in order to calculate percentage score

Discussion in 'Scripting' started by SIV, Apr 26, 2021.

  1. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    219
    Hello,

    I have a quizz system that each time a question is answered in wrong way it back at the end of the list and asked to the player again after list is finished (in a list called Questions)

    I have another list of bool (called answers) that adds either true or false based if the question is answered correctly or not.

    I have a third list of bool (called score) , the reason why i added the third list is because "answers" is been used to display all answers (even duplicated answers) at the end.

    All 3 works fine so adding answers to both "answers" and "score" is working fine and question answered wrong is added to the list at the end works fine too.

    The question :

    I want to calculate percentage of how many questions are answered correctly from the from first time , in order to do that i think best way is to make a for loop on both questions and score lists and remove the duplications from both (leave first one) then see the score list on how many true bool are there and use it for the calculate but im not sure how to do that in first place !

    The script is a bit complicated and contain other things thats why its useless to pass it here but i tried to explain as much detail as i can, so basically im looking for 2 things :
    - Remove duplciation from both "questions" and "score" lists
    - calculate percentage based on the remaining in "score" list if the element/item is true.

    Thank you !
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Right now you have a list of bools, which means they don't have a direct correlation with the answers other than position in the list.

    What I would do is simply get the Count of your questions list at the start and store that value. Then when a question is answered, check if your answer list count < the stored value. If it is, store your true or false. If it's not, then you know you have answered every question at least once and don't need to store true or false.

    Then the player can keep going through the questions they got wrong without it recording any additional T/F answers and you don't need to worry about duplicates.

    Then once you are done, you can loop through the answers and get a true count and the size of your list and calculate percents.
     
  3. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    219
    Yeah, it was as simple as that thank you !
    So adding answers to "score" will stop once its count reach total questions from start of the game.