A list of puns related to "Pseudocode"
looking for someone to help me continue my iterations in a question:
W=12
i) 1 2 3 4 Wi) 3 2 8 6 Vi) 2 4 3 5
im not sure how to continue after i find the V[i,w]=max{Vi+V[i-1,W-Wi] {V[i-1,W]
What programming language resembles pseudocode the most and has minimal complexity just like pseudocode?
I noticed that most solutions in the day 19 megathread used an O(n^2) algorithm for determining the maximum Manhattan distance between any two scanners. Of course, this is perfectly fine - the bulk of your runtime is going to be spent on an O(n^2) (or worse) search during part 1 for which scanners overlap in order to compute the scanner coordinates in the first place, so not optimizing part 2 won't make any huge difference to your overall time. But if you are trying to squeeze out every last microsecond of computer time, this tutorial shows pseudocode of how to do it.
The naive approach visits every pair of points, to track a running maximum (that is, n*(n-1)/2 computations of Manhattan distance):
ans = 0
for s1 in scanners:
for s2 in scanners:
if s1 != s2:
dist = abs(s1.x - s2.x) + abs(s1.y - s2.y) + abs(s1.z - s2.z)
ans = max(ans, dist)
But if you think of abs(a - b)
in terms of max(+(a - b), -(a - b))
, we can rewrite the 3-D Manhattan distance as a maximum of 2^(3) sums:
dist = max(+ (s1.x - s2.x) + (s1.y - s2.y) + (s1.z - s2.z),
+ (s1.x - s2.x) + (s1.y - s2.y) - (s1.z - s2.z),
+ (s1.x - s2.x) - (s1.y - s2.y) + (s1.z - s2.z),
+ (s1.x - s2.x) - (s1.y - s2.y) - (s1.z - s2.z),
- (s1.x - s2.x) + (s1.y - s2.y) + (s1.z - s2.z),
- (s1.x - s2.x) + (s1.y - s2.y) - (s1.z - s2.z),
- (s1.x - s2.x) - (s1.y - s2.y) + (s1.z - s2.z),
- (s1.x - s2.x) - (s1.y - s2.y) - (s1.z - s2.z))
Then we can rearrange the terms in each summation, to group all the s1 contributions on the left and s2 contributions on the right:
dist = max(+ (s1.x + s1.y + s1.z) - (s2.x + s2.y + s2.z),
+ (s1.x + s1.y - s1.z) - (s2.x + s2.y - s2.z),
+ (s1.x - s1.y + s1.z) - (s2.x - s2.y + s2.z),
+ (s1.x - s1.y - s1.z) - (s2.x - s2.y - s2.z),
- (s1.x - s1.y - s1.z) + (s2.x - s2.y - s2.z),
- (s1.x - s1.y + s1.z) + (s2.x - s2.y + s2.z),
- (s1.x + s1.y - s1.z) + (s2.x + s2.y - s2.z),
- (s1.x + s1.y + s1.z) + (s2.x + s2.y + s2.z))
Next, we can observe that although we are computing the maximum of 8 computations, we can pair up those computations. For example, the first and eighth terms involve the same two quantities (the sum of all s1 components, and the sum of all s2 components); for a paired term, we will get a maximum if the s1 contr
... keep reading on reddit β‘Is there a specific syntax I have to follow or can I just do
INPUT ArrayName[i]
?
Thanks!
I work online as a computer science tutor and I've been seeing a trend lately where students' first exposure to programming is not via Java or Python or any other real language, but rather via Pseudocode.
My students' first ever assignments remotely related to programming are typically to design various calculator programs in this Pseudocode. One example would be:
> Grade Calculator
>
> In this course you will have to complete a total of six tasks: three homework assignments altogether worth 40% of your grade, two mid-term exams each worth 15% of your grade, and one final exam worth 30% of your grade.
>
> Write a program which takes as input a student's name and the percent score he/she received (0-100 points) for each of these six tasks of the course. Calculate what this student's overall percentage grade is for the course, as well as the letter-grade he/she received (90-100 is an A, 80-89 is a B, 70-79 is a C, 60-69 is a D, and anything below 60 is an F). Finally, display as output the student's name, the percentage grade, and the letter grade that was calculated.
The problem is, these students have absolutely no concept of what "input" and "output" are, nor any concept of what variables are. They've never seen a console application before and so can't begin to imagine what this program would look like.
Sometimes, my students are terrible at math as well. Some of them don't even understand how percentages work (these are adult university students!), let alone how to calculate weighted averages, but that's another matter.
If this were an actual coding assignment, this would be no problem. I could introduce students to "Hello, world", how print() or System.out.println() can make a computer print out lines of text, how Python or Java understands math operations, exactly what variables are (which takes a lot more time to teach than you'd think!), and finally what it means for a program to be interactive & read input from you. This takes at least a full hour one-on-one to do properly, but it works well when students can see their programs do things.
By the end of my tutoring sessions on coding, even the.. ahem... "difficult" students at least have some idea as to how to proceed. They have something to work with.
With only Pseudocode though, ther
... keep reading on reddit β‘Just to be clear, I'm asking about structure here not syntax.
In this scenario there would be hundreds of villagers and dozens of professions to choose from. The idea would be that when you make this villager a farmer it sets Villager15Profession = Farmer
The function below with all the villagers loaded up with all these IF statements would run every second.
This seems simple, but very inefficient. Is there another way you'd structure how this is setup?
Just looking for big picture ideas here.
Villager15
If Villager15Profession = Lumberjack
Wood + Villager15LumberjackSkill
Villager15LumberjackSkill + .01
Villager15Exhaustion + .1
If Villager15Profession = Stonecutter
Stone + Villager15StonecutterSkill
Villager15StonecutterSkill + .01
Villager15Exhaustion + .1
If Villager15Profession = Farmer
Stone + Villager15FarmerSkill
Villager15FarmerSkill + 0.01
Villager15Exhaustion + 0.1
ELSE
Villager15Exhaustion - 0.2
I'm a second year uni CS student and I am doing terribly in my course on Systems programming, which uses C for the functional assignments. I've read the FAQ and I realize my issue would be resolved if I just knew more C, but alas, I hit a glass wall. I want to know if this is a normal thing to experience, and how I can better solve this issue. I experience paralysis (inability to translate logic to actual code) with other languages too, but a lot less (I use mainly python and java).
I was doing alright when pointers were introduced, and when structures were introduced. But when combining everything, and having a multilayered approach with 10+ different .C files, I get overwhelmed.
For context, the task is to use dynamically allocated structures (or unions) and a singly linked list to simulate a printer (print jobs represented by nodes in a queue). There's obviously lots of small twists but that's the overall gist. I can implement the structures (that's not rocket science) and some of the basic pointer concepts, but I am completely lost when it comes to complex pointer manipulation, memory management, and getting all the separate functions to work together. This was the last assignment of the course, and plenty of hints were given. Pseudocode for the functions were given out for free, basically the whole program was given out, just in logical steps.
Again, is this a major red flag for my programming foundations? If so, is this something I can fix? For reference, I can solve a few leetcode mediums in java, so I don't think I'm completely lost, but my inability to adapt to C is a bit worrying.
Thanks and sorry if this isn't a good question.
Hi, recently I stumbled upon a Khan Academy article[1] that showed this interesting but very short table that compares how a concept is expressed in pseudocode with how it could be/is implemented with Python:
Concept | Pseudocode | Python |
---|---|---|
Assignment | a β expression | a = expression |
Equality | a = b | a == b |
Inequality | a β b | a != b |
Repetition | REPEAT n TIMES | for i in range(n): |
Repetition | REPEAT UNTIL (condition) | while condition: |
List index | list[1] is first item | list[0] is first item |
It looked quite useful to me (note that i'm a beginner in coding overall), beyond being just some refresher/reinforcement. I imagined all kinds of coding concepts being presented with a (hopefully) self-explanatory pseudocode example and a comprehensive Python implementation, ordered from simplest to most complex. Does something like this exist anywhere? Thanks.
I have a bitwise operation which essentially extracts n bits from the t-th LSB in an unsigned int x of size 32 bits. It's pseudocode as follows :
extractBits (unsigned int x, int n, int t)
{
unsigned int mask = ((1<<n)-1)<<t;
final = x & mask;
}
I am now supposed to think of a function which is the reverse of this function. I cannot seem to come up with a pseudocode for such a function however. Any suggestions or help please? Thank you.
How often do you use pseudocode on your projects or at work? I have never actually learned how to use pseudocode, and wondering if it would help me make my programs easier to write. Is pseudocode really that helpful?
So we started learning algorithms and pseudocode for the algorithms but idk what pseudocode is it. In the lecture it's said its pascaloid-like but we are doing everything in C and C#. For instance we declare variables like:
x:integer
y:integer
...
for loops are weird they are written like.
for i=5;+1;10 so this in c would be for(i=5;i<10;i++) i think or its <=10 not sure.
Input and output are simple like:
input x
output y
What's this pseudocode and can I just write simple C language? It's weird, what if I can write it in an another way but the professor will not accept that way?
Looking for someone knowledgeable in algorithms and pseudo code. Vouches please. Itβs due in 4 hrs. Short questions. DM me.
Hi there.
I started school in web programming just over 2 weeks ago. Obviously still doing pseudocode. I'm having trouble with if, then and else.
I have a "paper" coming up Monday, for example. In our pseudocode, I can't determine whether the absence of "else" won't move onto the next "if". I don't even know if that's clear.
Any help would be appreciated. Thanks and cheers.
if game status == loading
for cars in garage
x = 0 // int going through the garage array assuming youβre using one
if (car(x).car show timer value == expired)
car(x).car show timer value = 0/whatever you use for available shit
car(x).car show is available = true
x = x + 1
else
x = x + 1
Itβs a temporary fix but since youβre taking literal months (I doubt youβre trying) please just add something similar to this. Itβs an absolute joke youβre getting paid for developing this game.
Get brokerage.Acct
If brokerage.Acct >3m
Define buyingPower(0.25) == onePosition
If onePosition == >0
then at_open(buy, onePosition == "SPY")
&& (buy, onePosition == "QQQ")
&& (buy, onePosition == "ARKK")
&& (buy, onePosition == "MO or DIAX or someOilStock")
Set sell.Conditions == null //because
//taxes; sell manually if you need to
If time is "December"
Then set sell.Conditions == TaxLossHarvest
Then in January GOTO "def buyingPower(0.25)"
Successfully initializing the brokerage.Acct subroutine so it doesn't fail on the if statement is the hardest part. The best way I know past it was to join FAANG or other Big Tech between 2014-2017 and not sell your RSUs until initializing this algo.
This account produces QQQ-like returns with smaller drawdowns, higher Sharpe and Sortinos, and a much higher cash yield of about 3%.
When answering algorithm questions, is there a specific syntax you must use when writing pseudocode? Do they accept syntax from different languages? I'm not very farmiliar with the IB psuedocode standard. For example, can I write a for loop this way:
>for (int i = 0; i < 10; i++) {
>
>print("hi");
>
>}
or this way:
>for i in range 10:
>
>print("hi")
or must I write it this way (ie IB psuedocode from answer key):
>loop for i from 0 to 10
>
>output "hi"
>
>end loop
Man, transposition tables are so complex for me. For my search program I've gotten the ab pruning and move ordering, which means that the only one left for me is the transposition table. I'm not exactly sure how to implement this, and I can't find any good resources for this. So, can someone please provide me pseudocode for minimax search with a transposition table? Thank you very much.
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.