Pseudocode and tens digit - pseudocode

Good day, I'm a complete newbie and need to solve a problem. I'm not asking someone to do my assignment for me I'm just stuck and If I can see the code I will be able to understand how it was done and create a new problem to check if I understand the solution.
Enter an integer value for the variable called 'num' that contains a value between 35 and 74. Determine if the 'tens' digit is equal to, greater than or less than the 'ones' digit.
I must use pseudo code but cant find anything in my text book.
I dont know how to create an variable with a number between 35 and 75
I know what's a 'tens' and 'ones' digit but have no idea on how to do the calculation.
If someone can please help me with this it will be much appreciated. The book I have is not helpful and I need help.
Thanks in advance
G

Related

Need to count the cells where time is later than a given value

direct to the point
heres the image
i need to get only the time thats over 9am and sum them all up at cell E35
this may sound easy to you guys and tell me it is, but im sorry, i just cant, im still a noob at this.
please help, thank you.
The formula you need is COUNTIF. In your case, put the following formula in cell E35:
=COUNTIF(E4:E34, ">09:00")
Updated
I think this is what you actually want:
=SUMIF(E4:E34, ">09:00") - COUNTIF(E4:E34, ">09:00") * TIMEVALUE("09:00")
This will add up all the times in the N cells that exceed 9:00 am and subtract N lots of 9 hours from the total.

Information Retrieval - Adjancey Matrix Graph Sketch, Teleportation Probability, Calculate PageRank

I am doing a few thing on Information Retrieval and have an exam coming up and I am absolutely clueless. First of, could anyone recommend me the shortest and best description possible for what PageRank actually is in Information Retrieval? Maybe even a good short video or your own description. I know Google use to, or did use it.
I know there are a lot of questions here but I could use as MUCH help as possible in a short length of time.
So my first question (taken from past papers, and making my own examples):
I am wanting to take a table such as:
A B C
A 0 1 0
B 1 0 1
C 0 0 0
And create a graph. I believe this is correct but unsure (I could use a "yes that is correct" or a "no":
And if I was given a graph such as:
The table would be:
A B C
A 0 1 0
B 0 0 1
C 0 0 0
Is that correct? If not, could I please get help and get it described somewhere? The lecture I am reading is not great at explaining and my lecturer isn't great at helping either.
Next I will probably be asked to use Teleportation Probability on the first table. This I desperately need help in. If the probability(the special a symbol)=1/2, does this mean multiply everything, including the 0's in the table such as 0x1/2? also 1x1/2? This is for the matrix of transition probabilities.
Next would be, how can I calculate PageRank from the above matrix. Using matrix multiplication. In words or in Pseudocode.
Another question I want to know is, will a user's page rank on twitter increase if they follow another user? I was assuming this would be a no because they are not following the user back?
Does a user's pagerank depend on how frequently you find said user if you start at a random user and click on another random persona and such till you find them? I assume this one is definitely not true. Because they might not be following said user.
I know this is a lot to ask. Does anyone have tutorials I can follow for either that are not complicated and I can look at and get it mastered today?
Thanks I really appreciate all your help. I know not one person can answer them all but can help provide assistance for some.
here's my stab at answering your questions:
good learning resource:
http://en.wikipedia.org/wiki/PageRank#Simplified_algorithm (no doubt you've see it already, but it's a pretty good one). Start there, understand the algorithm first, then do the implementation.
this might be a good simple method to implement?
http://pr.efactory.de/e-pagerank-algorithm.shtml
or this:
http://www.cs.princeton.edu/~chazelle/courses/BIB/pagerank.htm
I'm guessing you can program in Python (common school language), in that case you might be interested in a package for handling graphs which has pagerank calculations: http://networkx.lanl.gov/reference/generated/networkx.algorithms.link_analysis.pagerank_alg.pagerank.html. If you have to write your own pagerank algorithm (very doable), you could use that to check the results.
For the matrix -> graph conversion question: your professor needs to specify how directionality is encoded in the matrix. Does a 1 at B,C specify a link from B to C or from C to B? My guess would be B to C. If that's true, your first graph is wrong there, but the second graph is ok. Directionality is very important in PageRank.
I believe the Teleportation probability is the probability that a random walker executing a new step will jump to a random node in the graph. It's in the wikipedia page under "damping factor". I don't know how it ties into multiplying numbers in your matrix.
For the Twitter question - yes, I think you have it right. Linking to (or presumably following) a second person does nothing directly to the the first person's pagerank, but it likely increases the second person's pagerank. In practice, there could be secondary effects, like the second person noticing that the first person is interesting and following them back.
second to last question - yes, one formulation of the pagerank algorithm is as a random walk along links with the frequency of encountering a node (page) going into the pagerank.
good luck!

Sports tipping App comparing scores in Ruby

I have only just started to learn Ruby hoping one of you have some time to explain something to a complete newbie. I have been learning from Treehouse and Lynda (any other suggestions) and want to start testing what i know to write a small sports tipping app for my friends.
basically my theory is to
1. parse some data from an official site
2. get this into the format of a hash
3. iterate over the hash to see which score (value) is higher and which key (team) that is associated with to get a winner.
this is the core of functionality, however there is obviously code required around;
signing up and manage users
getting tips
giving results (and winners)
My first question is around iterating over a hash to compare the scores and get the winner.
what would be the most beautiful code to achieve this.
Hope you can help and thank you for your help its really appreciated, hope one day to be here with some skills returning the favour !
No offense but this post has a lot of explanation for what is really a very simple question: how to find the largest value in a hash.
That being said, you could do scores.max_by{|key,val| val} on a hash called scores. This is assuming the scores are integers, not strings. If the scores are strings you could do scores.max_by{|key,val| val.to_i} instead. That will return an array with the key (team name) as the first item, and the value (the score) as the second item.
See the original question from StackOverflow I posted above for more info.

Generating Bulls and Cows secret word with given n String inputs

I am stuck on this problem for quite a while, it is basically reverse engineering bulls and cow game.
Read more here: http://rosettacode.org/wiki/Bulls_and_cows
I am not able to develop a logic for the problem given below, if you can think of a solving approach please comment the same.
Problem Statement:
Given few clue words(of form ABCD/DBCA etc) and the number of cows and bulls for each word,program
should be able to work out the actual word by evaluating the given clue words and generate the output secret word.
TEST CASES:
Input:
4
DBCC 0 2
CDAB 2 1
CAAD 1 2
CDDA 2 0
Output:
BDAA
The idea is to reduce the space of possible solutions. Before you start, all 4^4 combinations are possible. After you read the first clue [DBCC 0 2 ], you can eliminate a number of possible solutions, in this particular example you can eliminate all states which have a D in the first place, all which have a B in the second place and so on. Just eliminate all possible solutions which do not "fit" the current clue.
Do this with each clue, until only one solution is left. Another interesting problem of course is how to generate good clue patterns.
The way I did it is:
1. Generate all possible words, put them in a list (array)
2. Randomly select one of them (first question)and ask for clues
3. Take the answer (let's say it is 2,1)
4. Start comparing that question with
first, second, ..., to the last word from the list
5. if they give the same clue: count them, plac

Need help psuedocoding a dice game and dont know where to even start [closed]

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!

Resources