/r/cs50
Demanding, but definitely doable. Social, but educational. A focused topic, but broadly applicable skills. CS50 is the quintessential Harvard (and Yale!) course.
O hai! This is CS50's subreddit.
CS50 is Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. Anyone may take CS50, even if not a student at Harvard.
Please Read before Posting
Status Page
Filter by Problem Flair (undo)
cash ⋅ caesar ⋅ credit ⋅ dna ⋅ filter ⋅ finance ⋅ houses ⋅ ide ⋅ mario ⋅ movies ⋅ plurality ⋅ project ⋅ readability ⋅ recover ⋅ runoff ⋅ scratch ⋅ speller ⋅ substitution ⋅ tideman ⋅ games track ⋅ web track ⋅ android track ⋅ iOS track ⋅
Filter by Other Flair (undo)
CS50-Law ⋅ CS50-Business ⋅ CS50-Technology ⋅ CS50-Games ⋅ CS50-Mobile ⋅ CS50-Web ⋅
/r/cs50
Hey there. Until now I have managed to fix and do every assignment by myself, but I've been going around in circles with this one and there is probably something I don't see.
I won't write an essay to bore you all; my problem seems to be simple, but I can't manage to fix it no matter what I try.
The program works; it catches all the misspells and properly shows the counts, as well as free all the space malloc allocated according to valgrind which is the most important.
However check50 still shows memory problems, more specifically, that a conditional jump is depended on uninitialized values on lines 35 and 41. It definitely has something to do with the char array of the nodes that are keeping the dictionary words.
The main thing I am wondering is how am I supposed to initialize these words as they are introduced with the load function I have written separately? What's even more confusing is that the array will never not be initialized, since the load function will load the dictionary every single time before we even get to checking the first word from the text.
I'd appreciate if someone could explain and point me into the right direction.
PS. idk how to copy the code to be a part of reddit. When I do it it doesn't work so these pictures will have to do. :D
I'm not sure exactly how to put this. But I've been wanting to get back into programming after a loooooong hiatus, so i started doing CS50x in my own time. However when i first began learning all those years ago i learned in visual studio, and I'm SORELY missing things like a simple compile button.
Is there a reason VSC doesn't have such a simple feature and as a newbie is there some reason i should specifically stick to VSC as opposed to upgrading to a higher end IDE?
(Keep in mind I'm just in week one, perhaps these questions will be answered later?)
this is the webpage that check50 outputs
https://submit.cs50.io/check50/cf505442355024405d968d311c62861f1ecb6295
doesn't check anything it just print's to log a lot of error of lines that are not even in my code, has it happend to someone else?.
I just want to let know someone that might want to fix it... but well I guess I will check my code for myself, for the time being.
and well hopefully is actually what I think it is and not my fault.
Hello!
I was playing around with my test file (that I use to do some experiments) to see how can I implement my version of speller and, when trying to understand why do we use malloc to create nodes to linked lists and other data structures instead of just a variable and I wrote this code to help me understand:
This code does not print "HI, WORLD!" as it should:
However, I discovered that after I make a 'printf' call in 'create_node', "HI, WORLD!" just magically appears:
My questions are:
1. Why making local variables of type 'node' and linking them to an global array does not make them global (i.e. I can't access them in other functions)? Does it has something to do with variables in the stack being deleted after execution of their local function?
2. Why by simply printing the addresses of the nodes, the code prints "HI, WORLD!" as intended?
Thanks in advance.
p.s. For those who are wondering, I know there are more head files than needed to this code, but it's easier to use external functions that way since I use it for testing.
In CS50P, do I need to complete the problem set after each lecture, or should I take the test after finishing all the exercises? The problem sets seem harder compared to what is taught in the lectures
Hi everyone,
I’m currently learning full-stack development through a Udemy course, and I’m looking for advice on how to better organize my notes, code, and ideas. Here’s where I’m at:
If anyone has been in a similar situation or has tips on how to organize learning materials effectively, I’d really appreciate your help! Thanks in advance.
I Found out that Django(from what i have seen on job posts) isn't really all that popular, and Node.js, PHP, PostgreSQL are in big demand, so does anyone have a course recommendation for me to learn more about it? (React course if you know any as well) I found on YouTube courses for them, but I felt asking you guys for a recommendation just incase there is a better course about these topic.
I am encountering a strange error in my code that I cannot figure out.
In the problem set 2 "substitution" when i run check50 all tests appear correct except this one:
":( encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key
expected "ciphertext: Rq...", not "ciphertext: Rq..."
It's strange because it seems like the expected output is correct so I don't know how to debug this.
This is my code:
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
// get key using CLI
int main(int argc, string argv[])
{
string key = argv[1];
// validate the key: check that the key exists
if (argc != 2)
{
printf("Usage: ./substitution KEY\n");
return 1;
}
// validate the key: check that key is long 26
if (strlen(key) != 26)
{
printf("KEY must contain 26 characters. \n");
return 1;
}
// validate key: check that characters are alphabetical
for (int i = 0; i < 26; i++)
{
if (isalpha(key[i]) == 0)
{
printf("KEY must contain only letters. \n");
return 1;
}
}
// make key all caps to make it case insesitive later
for (int i = 0; i < 26; i++)
{
if (islower(key[i]))
{
key[i] = key[i] - ('a' - 'A');
}
}
// validate key: check for duplicate char
for (int i = 0; i < 26; i++)
{
for (int j = 0; j < 26; j++)
{
if (i != j && key[i] == key[j])
{
printf("KEY must not contain repeated characters. \n");
return 1;
}
}
}
// prompt user for some text
string plaintext = get_string("Plaintext: ");
char ciphertext[26];
// encipher
for (int i = 0; i < 26; i++)
{
if (isalpha(plaintext[i]))
{
if (islower(plaintext[i]))
{
int x = plaintext[i] - 'a';
ciphertext[i] = key[x] + ('a' - 'A');
}
else
{
int x = plaintext[i] - 'A';
ciphertext[i] = key[x];
}
}
else
{
ciphertext[i] = plaintext[i];
}
}
// print cipher text
printf("ciphertext: %s\n", ciphertext);
}
!!<When I run check50, it says that my code for tabulate is unable to count votes when multiple candidates are eliminated and handle multiple rounds of preferences
void tabulate(void)
{
// TODO
int n = 0;
for (int i = 0; i < voter_count; i++)
{
while (candidates[preferences[i][n]].eliminated == true)
{
n++;
}
candidates[preferences[i][n]].votes++;
}
return;
}
For find_min, check50 says my code is unable to return the minimum number of votes for candidate
int find_min(void)
{
// TODO
// find first candidate not eliminated
int firstcandidate = 0;
while (candidates[firstcandidate].eliminated == true)
{
firstcandidate++;
}
int minvotes = candidates[firstcandidate].votes;
// find min votes
for (int i = firstcandidate + 1; i < candidate_count; i++)
{
while (candidates[i].eliminated == true)
{
i++;
}
if (minvotes > candidates[i].votes )
{
minvotes = candidates[i].votes;
}
}
return minvotes;
>!!<
This may be a question for a different sub but thought I'd ask here first in case others have gone down this route.
I've recently completed CS50x. I came into it as a complete beginner with zero CS o programming experience. I've started CS50P and plan to work through several of the CS50 courses over the next months (AI, web). I don't pretend to think I'll have any employable skills even after that, so out of curiosity, if I want to work towards being employable in some way, what should I do next? I hear there's a lot of great info at freecodecamp. But I'm assuming that realistically, with the current saturation, I would need some type of degree to actually become employable? I'm 40 years old and I've already done the traditional college and graduate school in a completely unrelated field. I'm trying to explore if there's any legitimate online programs I could pursue down the road.
Exclusively for js... Not talking about the Web dev one
If not... What's the best course similar to cs50
Everything compiles, but it doesn't pass check50 or my testing it. There is too much code for the duck to handle.
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
// Create a copy of image
RGBTRIPLE copy[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
copy[i][j] = image[i][j];
for (int k = 0; k < height; k++)
{
for (int l = 0; l < width; l++)
{
// Middle pixels
if (i != 0 && j != 0 && i != height - 1 && j != width - 1)
{
float total_red = copy[i + 1][j + 1].rgbtRed + copy[i + 1][j].rgbtRed +
copy[i + 1][j - 1].rgbtRed + copy[i][j + 1].rgbtRed +
copy[i][j - 1].rgbtRed + copy[i - 1][j - 1].rgbtRed +
copy[i - 1][j].rgbtRed + copy[i - 1][j + 1].rgbtRed;
float total_green =
copy[i + 1][j + 1].rgbtGreen + copy[i + 1][j].rgbtGreen +
copy[i + 1][j - 1].rgbtGreen + copy[i][j + 1].rgbtGreen +
copy[i][j - 1].rgbtGreen + copy[i - 1][j - 1].rgbtGreen +
copy[i - 1][j].rgbtGreen + copy[i - 1][j + 1].rgbtGreen;
float total_blue = copy[i + 1][j + 1].rgbtBlue + copy[i + 1][j].rgbtBlue +
copy[i + 1][j - 1].rgbtBlue + copy[i][j + 1].rgbtBlue +
copy[i][j - 1].rgbtBlue + copy[i - 1][j - 1].rgbtBlue +
copy[i - 1][j].rgbtBlue + copy[i - 1][j + 1].rgbtBlue;
float average_red = total_red / 8;
float average_green = total_green / 8;
float average_blue = total_blue / 8;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Top left
if (i == 0 && j == 0)
{
float total_red = copy[i + 1][j].rgbtRed + copy[i][j + 1].rgbtRed +
copy[i + 1][j - 1].rgbtRed;
float total_blue = copy[i + 1][j].rgbtBlue + copy[i][j + 1].rgbtBlue +
copy[i + 1][j - 1].rgbtBlue;
float total_green = copy[i + 1][j].rgbtGreen + copy[i][j + 1].rgbtGreen +
copy[i + 1][j - 1].rgbtGreen;
float average_red = total_red / 3;
float average_green = total_green / 3;
float average_blue = total_blue / 3;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Top right
if (i == 0 && j == width - 1)
{
float total_red = copy[i][j - 1].rgbtRed + copy[i + 1][j - 1].rgbtRed +
copy[i + 1][j].rgbtRed;
float total_green = copy[i][j - 1].rgbtGreen +
copy[i + 1][j - 1].rgbtGreen + copy[i + 1][j].rgbtGreen;
float total_blue = copy[i][j - 1].rgbtBlue + copy[i + 1][j - 1].rgbtBlue +
copy[i + 1][j].rgbtBlue;
float average_red = total_red / 3;
float average_green = total_green / 3;
float average_blue = total_blue / 3;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Bottom left
if (i == height - 1 && j == 0)
{
float total_red = copy[i + 1][j].rgbtRed + copy[i + 1][j + 1].rgbtRed +
copy[i][j + 1].rgbtRed;
float total_blue = copy[i + 1][j].rgbtBlue + copy[i + 1][j + 1].rgbtBlue +
copy[i][j + 1].rgbtBlue;
float total_green = copy[i + 1][j].rgbtGreen +
copy[i + 1][j + 1].rgbtGreen + copy[i][j + 1].rgbtGreen;
float average_red = total_red / 3;
float average_green = total_green / 3;
float average_blue = total_blue / 3;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Bottom right
if (i == height - 1 && j == width - 1)
{
float total_red = copy[i - 1][j - 1].rgbtRed + copy[i - 1][j].rgbtRed +
copy[i][j - 1].rgbtRed;
float total_green = copy[i - 1][j - 1].rgbtGreen +
copy[i - 1][j].rgbtGreen + copy[i][j - 1].rgbtGreen;
float total_blue = copy[i - 1][j - 1].rgbtBlue + copy[i - 1][j].rgbtBlue +
copy[i][j - 1].rgbtBlue;
float average_red = total_red / 3;
float average_green = total_green / 3;
float average_blue = total_blue / 3;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Top edge
if (i == 0 && j != 0 && j != width - 1)
{
float total_red = copy[i][j - 1].rgbtRed + copy[i][j + 1].rgbtRed +
copy[i + 1][j - 1].rgbtRed + copy[i + 1][j].rgbtRed +
copy[i + 1][j + 1].rgbtRed;
float total_green = copy[i][j - 1].rgbtGreen + copy[i][j + 1].rgbtGreen +
copy[i + 1][j - 1].rgbtGreen +
copy[i + 1][j].rgbtGreen + copy[i + 1][j + 1].rgbtGreen;
float total_blue = copy[i][j - 1].rgbtBlue + copy[i][j + 1].rgbtBlue +
copy[i + 1][j - 1].rgbtBlue + copy[i + 1][j].rgbtBlue +
copy[i + 1][j + 1].rgbtBlue;
float average_red = total_red / 5;
float average_green = total_green / 5;
float average_blue = total_blue / 5;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Left edge
if (i != 0 && i != height - 1 && j == 0)
{
float total_red = copy[i - 1][j].rgbtRed + copy[i - 1][j + 1].rgbtRed +
copy[i][j + 1].rgbtRed + copy[i + 1][j].rgbtRed +
copy[i + 1][j + 1].rgbtRed;
float total_green = copy[i - 1][j].rgbtGreen +
copy[i - 1][j + 1].rgbtGreen +
copy[i][j + 1].rgbtGreen + copy[i + 1][j].rgbtGreen +
copy[i + 1][j + 1].rgbtGreen;
float total_blue = copy[i - 1][j].rgbtBlue + copy[i - 1][j + 1].rgbtBlue +
copy[i][j + 1].rgbtBlue + copy[i + 1][j].rgbtBlue +
copy[i + 1][j + 1].rgbtBlue;
float average_red = total_red / 5;
float average_green = total_green / 5;
float average_blue = total_blue / 5;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Bottom edge
if (i == height - 1 && j != 0 && j != width - 1)
{
float total_red = copy[i - 1][j - 1].rgbtRed + copy[i - 1][j].rgbtRed +
copy[i - 1][j + 1].rgbtRed + copy[i][j - 1].rgbtRed +
copy[i][j + 1].rgbtRed;
float total_green = copy[i - 1][j - 1].rgbtGreen +
copy[i - 1][j].rgbtGreen +
copy[i - 1][j + 1].rgbtGreen +
copy[i][j - 1].rgbtGreen + copy[i][j + 1].rgbtGreen;
float total_blue = copy[i - 1][j - 1].rgbtBlue + copy[i - 1][j].rgbtBlue +
copy[i - 1][j + 1].rgbtBlue + copy[i][j - 1].rgbtBlue +
copy[i][j + 1].rgbtBlue;
float average_red = total_red / 5;
float average_green = total_green / 5;
float average_blue = total_blue / 5;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
// Right edge
if (i != 0 && i != height - 1 && j == width - 1)
{
float total_red = copy[i - 1][j].rgbtRed + copy[i - 1][j - 1].rgbtRed +
copy[i][j - 1].rgbtRed + copy[i + 1][j + 1].rgbtRed +
copy[i + 1][j].rgbtRed;
float total_green = copy[i - 1][j].rgbtGreen +
copy[i - 1][j - 1].rgbtGreen +
copy[i][j - 1].rgbtGreen +
copy[i + 1][j + 1].rgbtGreen + copy[i + 1][j].rgbtGreen;
float total_blue = copy[i - 1][j].rgbtBlue + copy[i - 1][j - 1].rgbtBlue +
copy[i][j - 1].rgbtBlue + copy[i + 1][j + 1].rgbtBlue +
copy[i + 1][j].rgbtBlue;
float average_red = total_red / 5;
float average_green = total_green / 5;
float average_blue = total_blue / 5;
image[i][j].rgbtRed = average_red;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtBlue = average_blue;
}
}
}
}
}
}
Where am I going wrong?
I've submitted my final project for CS50s programming with Python course, and it said it'll be graded within a few minutes. However, its been 2 hours now and nothings changed on my status page, I've not received any emails or comments or intimations anywhere either. Any advice on what my situation is, whom to contact, and where to look? thank you in advance for any help.
So, I finished cs50x last month and got the certified, but the course didn't disappear from edx, should I unenroll?
I just completed the CS50 course and am now thinking about building a web application. However, since the course didn’t cover a lot of details, I’m a bit confused about the idea and approach. I’d appreciate any guidance on how to proceed!
The codespace doesn't load :(
Hello , can anybody tell me how to use vs code on browser ?
Sometimes the programs that I make in the VSE automatically appear in my Github repository, but other times they don't. I can't think of anything that I'm doing that makes them show up. I've tried doing it manually but that doesn't work either. For example, I was working on Week 4 "Recover" earlier today and a version of that is backed up on Github, but not the final version I just completed. Is there a way to force this over, or set the frequency of backups?
I’ve just started CS50, I’ve done some programming before using Fortran90 and Python while studying Physics at University some time ago, but wanting to learn coding from a more fundamental starting point, as I was just sort of thrown tools that would help in simulations but didn’t really learn basics. I had never covered C and thought it would be a good place to start.
I’ve just completed the harder of the Mario problems from Pset1. I just tried to create an array with conditions for which character to print. I started using if and else conditions, but ran into an error when trying to use 2 if statements one after another. I looked at some documentation to see if you could impose 2 conditions in one statement. I came across using ‘&&’. This did what I wanted and then the code worked fine.
Can we use things from documentation that haven’t been covered so far in the course for a problem set? After completing and getting the correct output I looked for solutions online to see how they compared, and none seem to use this. I just wanted to know before I submit, otherwise I’ll have to start again and do it differently.
Thanks!
I am stuck at implementing the minimax function with alpha-beta pruning. This is were I'm at:
The instructions not to alter the prototypes of any of the functions. I have an idea to set up my hash table, but it requires changing the node structure a bit. Would this be alright, or should I not touch that either?
So after the the grades were archived, the page of grades doesn't show which assignments were passt and which are still not, is there a way to know .
and how to know that everything is passed and claim the certificate?
Thank you in advance
It is stated that the each jpeg is stored immediately after the previous one, but in the walkthrough video, Brian suggests that each image starts at the beginning of a block. So, I'm a little confused. Someone, help, please.
I really learned a lot from this material. In particular, the regular expression hint. It took some time to understand the syntax for regular expressions, but it was worth it. Using else after a try/except or a for/while loop was new to me and it is very useful.
I am trying to do the birthday pset in cs50 and am trying to make a delete function where a name you entered will be deleted from the database. Rest all of my features such as adding and displaying birthdays are working perfectly, except this one. Why would it be?
This is how i take the to be deleted entry from the user:
<h2>Delete a Birthday</h2> <form action="/" method="delete"><input type="text" name="deleted" placeholder="Name">
<input type="submit" value="Delete birthday">
</form>The following is how i try to remove the entry from the database but it does not.
if request.method == "DELETE":
name = request.form.get("deleted")
if not deleted:
return redirect("/")
db.execute("DELETE FROM birthdays WHERE name = ?", name)
return redirect("/")