Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6775103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:52:01+00:00 2026-05-26T15:52:01+00:00

I am having some trouble understanding this brute force approach. I am using Perl

  • 0

I am having some trouble understanding this brute force approach. I am using Perl to extract questions and their choices. All of the questions right now are being stored inside of an array. I am not sure what to do with the answers.

How should I store the answers and organize my code so it does something similar to this…

  1. Select the first option for the question. (So pass one, all the questions should have option A selected).

  2. Submit to check for correct answers.

  3. Parse answers, if the given answer was correct mark that as "correct" answer and forget trying to select any other choice for that question.

    Otherwise, continue through the list of answers for that question on the next pass.

So the next pass would pick the second answer for the that question, until after multiple submits it finds all of the "correct" answers via brute force.

I am having trouble how to store the answers and associate them with the question, cross them off as they are wrong or tag it "found".

I was thinking about using a hash. Please let me know any suggestions on how I should structure the code.

Thanks!

EDIT

Sample data —

So I am using a HASH method… my hash looks something like this:

print out of the hash :

question_123 => a,b,c,d
question_155 => a,b,c
question_234 => T,F

Now I have to find a way to go through each option until I find the correct answer for that question.

EDIT

To clarify somethings let us assume there is a pool of 10 questions. The user clicks "Begin Practice" which generates 4 random questions from the pool of 10. Thus, at this current state I have four questions with their answers. I go through and add these questions and their answers to a data structure (one from below… or using files to store them). Next I being to pick an answer. Then the user must submit these questions for review. Once the submit button is hit, the prompt says if question x is correct or incorrect. Based on this, the data structure must update which is the correct answer for that question.

Now to rinse and repeat. This time another four set of random questions is generated from that same pool. This time, two new questions are found so these must be added to the data structure. Similar logic should be used to find the answers. Also, each answer option (selection) always has an unique numeric value attached to it so my server can check the answer ID with the value. On my server side each question just has an ID and it’s associated right answer. Using my table would defeat the purpose of this experiment.

Visual of what is happening:

Pass One -- 4/10 Random Questions

1. Who is the US president?
21. Barrak
22. Chap
23. Jim
24. Nivea

2. How many states are there?
25. 99
26. 90
27. 51

3. What is the color of the sky?
28. blue
29. black
30. none

4. Is time relative?
31. False
32. True

So, on the first pass the selections should be like the following:

1 => a - 21
2 => a - 99
3 => a - 28
4 => False - 31

Hit the submit button. Server responds with :

1. Correct
2. Incorrect
3. Correct
4. Incorrect

Now update the data structures with correct answer found.

Program now requests new set of questions at the prompt. This time the server returns:

Pass Two -- 4/10 Random Questions

4. Is time relative?
31. False
32. True

6. What is not a plant?
65. Cow
66. Rose
67. Tree

1. Who is the US president?
21. Barrack
22. Chap
23. Jim
24. Nivea

8. What is a programming language?
99. C++
100. Tylenol
101. Mr.Monster

See, now on this pass two new questions arose. For these guys the first options have to be selected but for the repeated ones, the next up should be picked unless the correct answer has already been found.

So this will be sent to the server:

4. True - 32
6. Cow - 65
1. Barrack - 21
8. C++ - 99

The server responds with:

4. Correct
6. Correct
1. Correct
8. Correct

Same deal with the response. Hope this really clears things up. Also note that each answer will always have an unique numerical value attached to it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:52:02+00:00Added an answer on May 26, 2026 at 3:52 pm

    Associate the right answer and all possible options to each question:

    my %question = (
    
        question_123 => {
                          options => [ 'a', 'b', 'c', 'd' ],
                          answer  => 'b',
                        },
        question_155 => {
                          options => [ 'a', 'b', 'c' ],
                          answer  => 'b',
                        },
        question_234 => {
                          options => [ 'T', 'F' ],
                          answer  => 'F',
                        },
    );
    

    Then cycle through the options with a simple script:

    my %answers;
    QUESTION: foreach my $q ( keys %question ) {        # Loop over questions
    
        for my $option ( @{ $questions{$q}{options} } ) { # Try different options
    
            $answers{$q} = $option;
            next QUESTION if $option eq $questions{$q}{answer}; # Move on if correct
        }
    }
    
    # Print the answers
    print "$_ : $answers{$_}\n" foreach sort keys %answers;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
I'm having some trouble understanding the IF clause at the end of this function
I'm having some trouble understanding why this code won't work. I got it from
I am having some trouble understanding how to, using a bottom up parser and
I'm having some trouble understanding the differences between how Expressions and Funcs work. This
I'm having some trouble understanding a bit of code. I've got 2 classes Company
I'm having some trouble understanding Outlook terms (CommandBarPopup, CommandBarButton etc) like what is what
I've been reading through Programming Clojure, and I've been having some trouble understanding Stuarts
I'm very new to JQuery, and I'm having some trouble understanding how to do
I'm having some serious trouble understanding the view matrix in XNA. I've come pretty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.