Here's my question---
I want to create a Question System that helps me to pick out a random Question. I have two parameters: how many questions to ask, and how many unique questions.
For example, I have 6 unique Questions (1,2,3,4,5,6)
And I have to ask questions 10 times (1,2,3,4,5,6,1,2,3,4)
What logic I need is
I want it be random
"Every question should been picked at least one times"
"Each question shouldn't repeat at any time" example: (2,6,6,3,4,1,)<---the 6type of question is repeated at place 2 and 3.
My logic is poor....
Can anyone write me a Method can return an Array that contains like (3,6,5,1,2,4,6,2,1,3)?
Thanks for your help!
Make an array called 'chosen' which is the same size as the question array. Set each value of the chosen array to 0. Each time you randomly choose a question, accept it only if its chosen[n] value is 0, and then set chosen[n] to 1. When all values of the chosen array equal 1, then reset all values to 0.
Related
I'm newbie here.
I am currently trying to solve the problem regarding the sorting algorithm.
I will outline the situation:
we have 60 items. Variables of type A and B are written to these items. Variables A and B are stored randomly. Variables A and B have another parameter X, which indicates their material. (material may change during storage). Items are then taken one by one to another item with 10 elements, where we try to achieve the storage of 2 or 3 of the same types of variables A or B from the same material on one element. After saving the required number of variables with the same properties, they are subsequently removed from this item.
I tried to describe it as simply as possible, but maybe I should have described it with a real example.
It can be imagined as a warehouse that has 10 elements and takes from a conveyor that has a capacity of 60 elements. As soon as the warehouse has the same type of goods of the same material on one element, it dispatches the goods and releases its position.
So I want to remove the elements from the conveyor as efficiently as possible and sort them in stock according to requirements.
It occurred to me to sort by case for all options.
Thank you for all your ideas and comments. If it's not very clear, then I apologize and try to explain it differently. :)
We have a matrix of questions with 12 field label variable (resources) and options for this matrix are - Strongly disagree -to strongly agree. I want develop next question based on "Strongly agree answer' and asking participants to rank those variable/sources.
'The final set of questions relate to return to work resources the MDT team may have offered while you were still in the recovery unit. Please indicate how much you agree with the following statements.'
1 Help with CV
2 Apply funding .....
3
......
12 Adaptive equipment
For the following question - is it possible to pull out variables/ resources that participant choose as strongly agreed and ask them to rank them 1 to 5.
Thanks,
JM
If I understand correctly, you have a matrix of 12 fields with strongly agree to strongly disagree, and for each of those that are marked strongly agree, you want to have the respondent rank them from 1 through to 5.
What you can do is have another matrix field that asks respondents to select a choice between 1 and 5 for each of the 12 statements in the first matrix. Then, for each statement in the second matrix, add branching logic to only show it if the corresponding statement in the first matrix was strongly agree. Finally, set the matrix to 'Ranking'; this will only allow a single response per column (in addition to only a single response per row). This will mean a user may only have one 1, one 2, etc.,
Here's what that looks like in the designer:
However, there are problems with this. First, there is nothing to prevent someone selecting strongly agree to more than 5 choices, meaning there will be statements that cannot be ranked. Maybe this is good; maybe you only want them to be able to rank 5 and the way to handle that is to only provide 5 columns to rank. Here's a screenshot of a record with 6 statements to rank. Notice the last cannot be ranked or it will displace another statement's ranking:
The reverse is also true, if someone answers strongly agree to less than 5 statements, they will still see 5 columns to rank the less than 5 statements, so you might have 1, 2, 3, or it might be 1, 3, 4. This screenshot shows three statements being ranked, leaving two rank positions unfilled.
The problem is that the number of choices in a ranking matrix field cannot grow or shrink depending on the number of statements in it.
Here is my situation, i am currently creating a Yahtzee game using Turbo Pascal Language in Lazarus IDE and i am up to the scoring side of the developement, i have already completed the Lower section of scoring and i have started the Higher section but i need some help writting a procedure to check for a three of a kind, my initial thought was to use an array and load the random numbers for the dice values and then use a loop function to check for 3 equal numbers but i'm not very confident in this area. Could i get some help ? I'm not asking for code, although it would be helpful, just a push in the right direction.
My dice integer value variables are, "Dice1" , "Dice2" , "Dice3" , "Dice4" , "Dice5" , "Dice6"
I think the conceptually simplest approach is to have an array of six counters - one for each possible value - that you initialize to zero and then loop over your dice array and increment the counters with each die's value.
You can then check if any of the counts becomes 3 (or more).
Or sort and then iterate to see if you have 3 same values in a row. The sorted array with dice values is also usable for the other detections like street, Carré (four of a kind), Yathzee etc.
I have a list of questions. Each question have at least 2 answers to choose from. There is only one option that is right, for now.
Having the answers in the same order teaches the students of where the answer is located instead of learning the actual answer to the question. Hench shuffling the answers is good.
Problem: I use the index to keep track of the correct answer for each question. This way wont work with shuffling the answers.
Current question structure:
question structure {
correct answer, index of where the correct answer is in the array below
list of answers, simple array of strings
}
When shuffling (Fisher–Yates shuffle) the correct answer is moved in the array, the index change.
One possible solution is to switch the structure to this but it would be inefficient:
question structure {
list of answers
}
answer structure {
boolean correct answer (true, false)
string answer
}
Is there a better way of doing this?
How do I keep track of the correct answer in the array?
I was pondering of keeping an array of the answers in one list then use a map and shuffle that map. Seems like overkill, complicated and memory and cpu hungry. That way i could keep the index to the correct answer.
I've stared myself blind of this problem.
Note: This program prototype is written in C# but it shouldn't matter that much.
During the shuffle, the algorithm is choosing two indices and exchanging the array elements at those indices. All you need to do is check if the current answer index is one of those indices. If so, change it to the other one.
eg
// Given two elements i, and j which will be used to swap, update answer index
if answerIndex = i then
answerIndex <- j
else if answerIndex = j then
answerIndex <- i
end
Well, if it was me, I would identify each answer with an int ID, and then just identify the correct answer by the ID (Something like int Correct_ID. So, when the user chooses a question, all you have to do is compare Correct_ID and the chosen question's ID, regardless of how many times you shuffle.
It's similiar to the boolean idea, but opens other possibilities: if you perform other actions on the answers, this ID could also come in handy, since it's quicker to compare int's than string's.
(If I remember a situation to serve as an example, I'll update, can't come up with one at the moment)
Well, here's a Python example.
>>> items = [
... (0, 'Apple'),
... (1, 'Banana'),
... (2, 'Orange'),
... (3, 'Pear'),
... ]
>>> import random
>>> random.shuffle(items)
>>> items
[(1, 'Banana'), (2, 'Orange'), (0, 'Apple'), (3, 'Pear')]
>>> for key, value in items:
... print key, value
...
1 Banana
2 Orange
0 Apple
3 Pear
>>>
The key point being you can shuffle records, where each record has an ID associated with it, not just the string value.
You can store unique IDs for each item, or just mark one of them as the "correct" answer (so each item would have a True or False, and only one would be True).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am a beginner IT student and doing a project for my programming logic and design class. I need to create a psuedocode for a dice game that allows you 2 rolls with 5 dice. On the first roll you get to pick 1 die to keep. The computer then rolls the other 4 dice and calculates you're score based on what you rolled. There are 3 rolls per game and the total score is displayed. Rolling nothing takes points away. The scoring is: 2 of a kind=50 points, 3 of a kind=75 points, 4 of a kind=100 points and nothing subtracts 50 points.
The whole problem I have is I dont even know where to start. I think I need this to repeat 3 times, but what variables do set? Please someone help me, I cant really ask my instructor because he is outside smoking the whole class and everything I have learned about this class mostly came from the internet and reading the book. I dont want to fail this class...someone please help me through this???
First of all don't panic. What you are about to do is break the task down into small steps.
Pseudo-code is not really code - you can't use it directly as a language, but instead it is just plain english to describe what it is you are doing and the flow of events.
So what are the initial steps to get you started?
Ask yourself what are the facts, what do you know exist in advance. These are the "declarations" that you make.
You have five dice. Each is a seperate object so each gets it's own variable declaration
dice_1
dice_2
dice_3
dice_4
dice_5
Next decide if each die has an initial value
dice_1 initial value = 0
etc...
Next you know that you have to throw the dice a number of times. Throwing is a variable with an initial value
turns initial value = 2
turns_counter initial value = 2
You should be getting the idea now. Are there other things you should declare in advance? I think so!
Next you have to decide what it is you are doing step by step. Is it just a sequence of events or is it repeating? If it's repeating how do you get it to stop?
While turns_counter is less than 2
Repeat the following:
turns_counter = turns_counter + 1
if turns_counter = 2
Throw. Collect_result. Sum_result.
else
Throw. Collect_result. Sum_result. Remove_a_dice.
endif.
perhaps you have to tell the reusable code which objects they are going to be working with? These are parameters that you pass to the reusable code Throw(dice_1) perhaps also you need to update some variables that you created? do it in the reusable code with or without passing them as parameters.
This is by no means complete or perfect, but you should get the idea about what's going on and how to break it down. It could take quite a while to do.
Most languages provide a pseudo-random number generator function that returns a random number within a certain range. I would start by figuring out which language you'll use and which function it provides.
Once you have that, you will need to call it for each roll of each dice. If you are rolling 5 dice, you would call it 5 times. And you would call it 5 more times for a second roll.
That's a start anyway.
You have already almost answered the question by simply writing it down here. There is no strict definition of what pseudocode is. Why don't you start by re-writing what you've described here as a sequence of steps. Then, for each step simply refine that step further until you think you've made it as fine-grain as you like.
You could start with something like this:
Roll 5 dice.
Pick 1 die to keep.
Rolls the other 4 dice
Calculate the score.
// etc...
Quite weird to think that it's easier to ask SO than your instructor! :)
The easiest way to get started on this is to not rigorously bind yourself to the constraint of a specific language, or even to pseudocode. Simply, in natural English, write out how you would do this. Imagine that YOU are the computer, and somebody wants to play the game with you. Just imagine, in very specific detail, what you would do at each potential step, i.e.
Give the user 5 dice
Ask the user to roll them
From that roll, allow the user to pick one die to keep
...etc. Once you have done this, and you are sure it is correct, start transforming it into pseudo code by thinking about what a computer would need to do to solve this problem. For instance, you'll need a variable keeping track of how many points the user as, as well as how many total rolls have occurred. If you were very specific in your English description of the problem, this should mean you basically only need to plug pseudo code into a few sentences you already have - in other words, you're just substituting one type of pseudo code for another.
I'd like to help, but straight-up providing the pseudo code wouldn't be very helpful to you. One of the hardest steps in beginning programming is learning to break a problem down into its constituent elements. That type of granular thinking is unintuitive at first, but gets easier the more time you spend on it.
Well, pseudo-code, in my experience, is best drawn up when you pretend you're writing up the work for someone else to do:
THINGS WE NEED
Dice
Players
Score
THINGS WE TRACK
Dice rolls
Player score
THINGS WE KNOW
(These are also called constants)
Nothing (-50)
2 of a kind (+50)
3 of a kind (+75)
4 of a kind (+100)
All of these are vital tools to getting started. And...well, asking questions on stackoverflow.
Next, define your "actions" (things we do), which utilizes the above known things that we will need.
I would start the same place I always do: creating our things.
def player():
"""Create a new player"""
def dice():
"""Creates 4 new, 6 sided dice"""
def welcome():
"""Welcome player by name, give option to quit"""
def game():
"""Initialize number of turns (start at 0)"""
def humanturn():
"""Roll dice, display, ask which one they'll keep"""
def compturn():
"""Roll four dice"""
def check():
"""Check for any matches in the dice"""
def score():
"""Tally up the score for any matches"""
def endturn():
"""Update turn(s), update total score"""
def gameover():
"""Display name, total score, ask for retry"""
def quit():
"""Quit the game"""
Those are your components, all fleshed out in a very procedural manner. There are many other ways to do this that are much better, but for now you're just writing the skeleton of an idea. You may be tempted to combine many of these methods together when you're ready to start coding, but it's a good idea to separate everything until you're confident you won't get lost chasing down a bug.
Good luck!