Pseudo code example [closed] - pseudocode

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 6 years ago.
Improve this question
I am new to programming in general and I am trying to learn the basics of it. Could someone explain me the concept of Pseudo code. I have already done some research but an additional help would be great. As an example, what would pseudo code for making a peanut butter and jelly sandwich would look like?
-Thank you.

Pseudo code is a simplified language designed to express ideas in programming without using the syntax of a specific programming language. It is a way to express algorithms in a compact and understandable form, making it easier to discuss and understand the code without actually writing it.
Pseudo code can either consist of real code-like examples, or just pure text.
An example of a pseudo code for making a PBJ could look something like this:
MakePBJRoutine(input: peanut butter, jelly, bottom bread, top bread)
Begin routine:
Take bottom bread.
Spread peanut butter on bottom bread.
Spread jelly on bottom bread.
If want more jelly:
Spread jelly on bottom bread.
Place top bread slice on bottom bread
Return finished sandwich
End routine
Meanwhile, it could also look like this.
makePBJroutine(input: P, J, TB, BB; Out: PBJ) {
BB <- P;
BB <- J;
If(BB.J < PreferredJellyAmountConstant){
BB <- J;
}
PBJ <- (BB <- TB);
Return PBJ;
}

Related

How to make snake game with random walls appearing? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I almost wrote a snake game, but I still can’t get one of the main ideas.
I would like for random walls to appear on the map during the game, as it happens in google snake game in wall mode. Here is the link to game.
My question is only about the idea of ​​the algorithm and it's disconnected from a specific programming language.
The problem is that absolutely random walls could create “unreachable” places in the level, such as enclosed spaces, where the snake could not get theoretically. So how to check such "unreachable" places on a level and not create incorrect walls?
PS: Sorry for my poor English.
Just do a google search for the "A*" Algorithm. The head of the snake is your starting point, the apples your end point and the walls your obstacles. (of course you would have to think about, how to get around the problem of interfering with your tail)

How to create random incongruous shapes that don't overlap each others in P5.js [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 5 years ago.
Improve this question
I'm looking to create shapes like this :
https://www.lucegallard.com/?lightbox=dataItem-isiz1h39
But they have to be generated at random and never overlap. It would be too easy to just use beginShape() and curveVErtex(x,y), etc.
Plus the result would we static, it needs to be changed easily and randomly. My question is "is there a function to create 'weird' ellipses?" or "Could anyone help me with an algorithm to achieve this?"
Thanks allot in advance!
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:
You need to break your problem down into smaller pieces and take those pieces on one at a time. Try to create a program that just generates a single random shape. Then try to add a second randomly-generated shape that doesn't intersect with the first shape.
Think about how you would describe this program to somebody who can't see the website you've linked in your post. Try to describe it in as much detail as you can. Pretend you have a friend who has never seen what you're talking about. Can you write down a set of steps that this friend could follow to draw what you're talking about? When you have those steps written down, that's an algorithm that you can start thinking about implementing with code.
A simple check would be for each new point you generate, check whether it's inside any previous shapes. If so, go back and pick a different new point. That will at least get you started going in a direction.
If you get stuck, please post a MCVE along with a more specific technical question. Good luck.

Writing an algorithm to complete a checklist, where to 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 7 years ago.
Improve this question
I'm completing a dissertation in health economics and would like to explore the possibility of using an algorithm to answer a checklist that I manually filled in during my research.
The checklist is a 24-item checklist which asks questions such as "Was a discount rate reported?". Now, the articles I've been reviewing tend to be very codified. That is, there are only a few ways that they report an answer (e.g. "we discounted at 3% in this evaluation").
Theoretically, I think it would be possible to write a program that could search text and fill out the majority of these checklist items. However, I have very little experience in programming. As far as I can see, a program like this would involve writing an algorithm of sorts, but that is where my knowledge ends.
Particularly, I would like to know
- Is this possible?
- If so, how would I go about exploring this further? Ideally, I'd like to get to a point where I could play around with writing an algorithm to look through my database.
This could definitely be done with simple logic and parsing, but the key to it would be that the manual entries are consistent in the way that they are "codified".
For example, you'd parse your line for a specific token (or validation word).
In your case above you could parse word for word the string: "we discounted at 3% in this evaluation"
Code wise we could implement a basic logical comparison to each word parsed in the string.
if(currentWord is equal to "discounted")
create a checkmark.

the advantages and disadvantages of multiple-line comments and one-line comments [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Many contemporary languages allow two kinds of comments: one in which delimiters are used on both ends (multiple-line comments), and one in which a delimiter marks only the beginning of the comments (one-line comments). Discuss the advantages and disadvantages of each with respect to criteria (readability, writability, reliability, cost).
There's no right answer here, they differ in a personal or style-wise way of coding.
With both you have a easy to write/read comment. The comment may be as long as you want, but generally short and precise comments are better, otherwise you would only be rewriting code as comment.
//assings 10 to x will make everything happier // the code won't change (further reading)
x = 10
if (x == 10)
happy++
How did this comment helped future users?
With multiple lines, though, you can write a little text, but reading it would be a little extra work if you still had to read (and understand) the code.
It won't change how programmers will read them, but they sure help when you have more than one line of comment (like reference URL's) and don't want to start every line with a comment markup.
I, personally, like multiline code for a simple reason: it agroups logical parts together
//*assings 10 to x will make everything happier //the code is on
x = 10
if (x == 10)
happy++
//*/
Now I can easily turn the code betwen those comments on and off that part of the code (for testing, for instance) only by changing the first "/". It would be a advantage of multiline.
/*assings 10 to x will make everything happier // the code is off
x = 10
if (x == 10)
happy++
//*/

Style of writing conditional operators [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What is considered more appropriate style of writing conditional operators?
if(1){
puts("Hello")
}
or
if(1) puts("Hello")
Similar aspects of coding style are welcome too.
That's all depends on your preference, that's why we rarely see people code in the same style.. Moreover, it depends on which programming language you're using.. IMHO, the important thing in coding is code readability and comments, so when your BOSS asks other people to help or develop your code. He /she will spend the least amount of their time to understand your code..
If you ask specifically from your example above, I would prefer the first one.. Because in my OPINION, imagining the WHOLE code, that one will give better readability. HOWEVER, some people may argue that it will spend some of your time typing those brackets over and over..
As per the PSR standards any structure must always enclose the code in parentheses.
The body of each structure MUST be enclosed by braces. This standardizes how the structures look, and reduces the likelihood of introducing errors as new lines get added to the body.
from the official website
Please have a look under control structures section http://www.php-fig.org/psr/psr-2/

Resources