/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
Would I not get the certificate? I have been working in pset for weeks and now its annoying me how check50 is still showing frowns even when the answer is correct acc to schema
I'm new to programing so i apologize if this is a stupid question.
i was trying to figure out if i could have autosuggest vs autocomplete. from what i found, the pylance extension can do that and it is already installed in the codespace, but for some reason it is not suggesting anything. i disabled all extensions other than python, python debugger and pylance but it still did not work.i also setup a different codespace in github with just python, python debugger and pylance extensions and it worked there perfectly. i searched this subredit but couldnt find anything related to my problem.
I had spent several hours thinking as to where should I declare and calculate the margins. In the requirements it's stated that I shouldn't modify existing code. So at first, I thought I should declare it in the sort_pairs function, cause it is where they are used. But the code kept getting pretty big and ugly. And then I thought why shouldn't I just create it when I was populating the pairs array in the add_pairs function. But even then after sorting the margins array, I realized that it won't be corresponding with the names. And here where I tried to find how others implemented it, a lot of people were storing it in the pairs (breaking the very first problem that drove to this point). So my question is can I add margins/strength to the pairs, and if I do, would I be able to swap the members of pair array, including its other elements?
I just have to submit the project and get the certificate, but I am wondering how to specify the name that I want to appear on the certificate. I do not want a strange name to appear like the one I put on GitHub.
When I was newer to programming last year I started CS50x but the difficulty curve was to advanced for me at the time. I have since completed other courses (including CS50p) and am having issues with progress since starting again.
I had previously completed the first three weeks of CS50x and the progress had clearly been passed over to this years course as on my progress screen it showed 3 out of 11 weeks completed and green.
Today I have submitted the PSETS for week one and the progress has dropped down to 2 out of 11 weeks complete. I have attached a screen shot. For clarity I have not resubmitted a scratch project but I have submitted both the lab from week one, hello, mario and cash.
During CS50p the progress was saved immediately, I am assuming it is the same for CS50x?
Thank you.
I am not getting check sum that I want
For eg for 124 I should get 9 instead I am getting 8. Please help
I am currently stuck on the 12th task of the problem "Movies". The 12th task requires you to write a SQLite query that returns a table of all the titles of the movies where both Bradley Cooper and Jennifer Lawrence starred. I decided to break down the problem into three smaller queries:
SELECT movie_id FROM stars WHERE person_id IN (SELECT id FROM people WHERE name = 'Bradley Cooper');
The first query returns a table of all the IDs of the movies where Bradley Cooper stars.
SELECT movie_id FROM stars WHERE person_id IN (SELECT id FROM people WHERE name = 'Jennifer Lawrence');
The second query returns a table of all the IDs of the movies where Jennifer Lawrence appears.
So I should look for the titles of all the movies where the ID is in both of the the tables above. I expressed this in the following way:
SELECT title FROM movies where id IN
(SELECT movie_id FROM stars WHERE person_id IN
(SELECT id FROM people WHERE name = 'Bradley Cooper'))
AND (SELECT movie_id FROM stars WHERE person_id IN
(SELECT id FROM people WHERE name = 'Jennifer Lawrence'));
However, when I run the third query, all it returns is the titles of all the movies where Bradley Cooper appears, completely ignoring the second part with Jennifer Lawrence. What is it that I am doing incorrectly?
Bit of an embarrassing post, but I made a beautiful website that I'm trying to push live with little to no success.
The site uses a similar structure to the CS50 Finance site. It's all built on Flask and uses elements of HTML CSS and JavaScript.
I realised I can't host it directly on GitHub because it uses Python, so I've been trying to use PythonAnywhere, but after many hours of trying to set it all up and many youtube video's, I've gotten nowhere.
Has anyone had similar frustration? Any suggestions on overcoming this final challenge?
Can someone please explain this in layman's terms? It was used in section 1 when Carter did the left aligned Mario pyramid (void print_row) and David is demonstrating it in lecture 2 during the debugging part. Is it absolutely necessary and an essential line to make the code work? I get why the prototype needs to be placed in the beginning so it tells the later program that it is coming. Is there no alternative ? It was not used, for example, in the Mario block file where you got to choose the size. I cannot figure out how it works exactly or why we would even use it if there are other simpler ways? Even more confusing is that the prototype is at the top and it is defined at the bottom, but the code reads from top down and executes that way with it being used in the middle of those two >>>print_column(h). Why does defining it at the bottom make sense? This little thing really has me baffled, thanks in advance if you can educate me on this.
I have submitted the google form at the end of the project 4 (network) and i didn’t receive any confirmation mail ? Should I resubmit the form again ?!
And yes i have checked my spam/junk mail and nothing there
having trouble with tkinter. anybody know why im not getting any window????
i have version 8.6
Just started cs50x and get a warning about academic honesty. Is this normal?
code snapshot. it passes check50 when i make the change in subject.
Segmentation fault happens on line 33 (Sprintf function)
If the largest possible number for a long variable is ~2B, which is 10 digits, how does a 16 digit credit card number fit in a long variable?
I am going to complete a project before the end of the week.
I am posting this because I need a reminder that this is something I need to do. I don’t want to procrastinate and I want to be more productive.
It's outputting the right answers but I seem to have to use ctrl-d in an empty line to activate the EOFError which doesn't seem to be the way it is supposed to work from the hints in the problem description. I should be able to hit ctrl-d with my last item and it will print the total right? Any suggestions?
Hello, as the title specifies, codespace debugger is not working, gives the following error.
Tried restarting the codespace but hasn't worked.
Would appreciate any suggestions to fix this.
Hello everyone.
I discovered/started CS50 a couple of weeks ago and I'm loving it. The problem is that I combine it with other things and I start to think that I don't know if I will arrive in time to deliver everything.
My question is, is it saved until you arrive for the next course or do you have to do the projects again? And if they have to be done again, are they the same?
I don't really know how the course works in this case.
Thank you
Below is my speller solution, which i'm trying to get to work. (have already solved once with not so great time). The indexing seems to be correct both in loading and while check but the ptr in check opens some other index than the one calculated above it. I don't know where my logic goes wrong. Suggestions are welcome.
edit- the result identifies 80% of the words as misspelled.
(Also why does the code duplicate when pasting here?)
// Implements a dictionary's functionality
#include <cs50.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "dictionary.h"
// Represents a node in a hash table
typedef struct node
{
char word[LENGTH + 1];
struct node *next;
} node;
// TODO: Choose number of buckets in hash table
const unsigned int N = 27;
// Hash table
node *table[N][N][N];
//count
int count = 0;
// Returns true if word is in dictionary, else false
bool check(const char *word)
{
// call hash function
int index = hash(word);
int j = (index % 100);
index /= 100;
int k = (index % 100);
index /= 100;
int i = (index % 100);
index /= 100;
node *ptr = table[i][j][k];
// from the hash check the singly linked list till word is found
while (ptr != NULL)
{
if (strcasecmp(ptr->word, word) == 0)
{
return true;
}
else if (ptr->next == NULL)
{
return false;
}
ptr = ptr->next;
}
return false;
}
// Hashes word to a number
unsigned int hash(const char *word)
{
// TODO: Improve this hash function
int i = 0;
int j = 0;
int k = 0;
if (strlen(word) == 1)
{
i = toupper(word[0]) - 'A' + 1;
}
else if (strlen(word) == 2)
{
i = toupper(word[0]) - 'A' + 1;
j = toupper(word[1]) - 'A' + 1;
}
else
{
i = toupper(word[0]) - 'A' + 1;
j = toupper(word[1]) - 'A' + 1;
k = toupper(word[2]) - 'A' + 1;
}
int index = i*10000 + j*100 + k*1;
return index;
}
// Loads dictionary into memory, returning true if successful, else false
bool load(const char *dictionary)
{
//loop till the end of dictionary
FILE *file = fopen(dictionary, "r");
if (file == NULL)
{
return false;
}
// read each word loop
char buffer[LENGTH + 1];
while (fscanf(file, "%s", buffer) != EOF)
{
//allocate memory and buffer
node *n = malloc(sizeof(node));
//scan and copy word to node
strcpy(n->word, buffer);
//assign index to node
int i = 0;
int j = 0;
int k = 0;
if (strlen(n->word) == 1)
{
i = toupper(n->word[0]) - 'A' + 1;
}
else if (strlen(n->word) == 2)
{
i = toupper(n->word[0]) - 'A' + 1;
j = toupper(n->word[1]) - 'A' + 1;
}
else
{
i = toupper(n->word[0]) - 'A' + 1;
j = toupper(n->word[1]) - 'A' + 1;
k = toupper(n->word[2]) - 'A' + 1;
}
n->next = NULL;
//conditional node index assignment (singly linked list)
if (table[i][j][k] == NULL)
{
table[i][j][k] = n;
count++;
}
else
{
n->next = table[i][j][k];
table[i][j][k] = n;
count++;
}
}
fclose(file);
return true;
}
// Returns number of words in dictionary if loaded, else 0 if not yet loaded
unsigned int size(void)
{
// TODO
return count;
}
// Unloads dictionary from memory, returning true if successful, else false
bool unload(void)
{
// TODO
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
for (int k = 0; k < N; k++)
{
node *ptr = table[i][j][k];
while (ptr != NULL)
{
node *next = ptr->next;
free(ptr);
ptr = next;
}
}
}
}
return true;
}
I had an internet server error due to the sell function. i tried everything. it worked when i pass shares in de.execute as a postive number. can anyone help??
def sell():
"""Sell shares of stock"""
if request.method == "GET":
user_id = session["user_id"]
symbols_user = db.execute("SELECT symbol FROM transactions WHERE user_id = ? GROUP BY symbol HAVING SUM(shares) > 0", user_id)
return render_template("sell.html", symbols=[row["symbol"] for row in symbols_user])
# Handle POST request to execute the sell transaction
else:
# Get symbol and shares from the form
symbol = request.form.get("symbol")
shares_input = request.form.get("shares")
# Validate the input
if not symbol:
return apology("Must provide a stock symbol")
stock = lookup(symbol.upper())
if stock is None:
return apology("Symbol does not exist")
# Validate shares input
try:
shares = int(shares_input)
if shares <= 0:
return apology("Shares must be a positive integer")
except ValueError:
return apology("Shares must be an integer")
user_id = session["user_id"]
# Get user cash balance
user_cash_db = db.execute("SELECT cash FROM users WHERE id = ?", user_id)
user_cash = user_cash_db[0]["cash"]
# Get total shares owned by the user for the specified symbol
user_shares = db.execute("SELECT SUM(shares) AS shares FROM transactions WHERE user_id = ? AND symbol = ? GROUP BY symbol", user_id, symbol)
user_shares_real = user_shares[0]["shares"] if user_shares else 0
# Validate if user has enough shares to sell
if shares > user_shares_real:
return apology("You don't have enough shares to sell")
# Calculate the transaction value and update cash balance
transaction_value = shares * stock["price"]
updated_cash = user_cash + transaction_value
# Update user's cash in the database
db.execute("UPDATE users SET cash = ? WHERE id = ?", updated_cash, user_id)
# Record the transaction
date = datetime.datetime.now()
db.execute("INSERT INTO transactions (user_id, symbol, shares, price, timestamp) VALUES (?, ?, ?, ?, ?)",
user_id, stock["symbol"], -shares, stock["price"], date)
# Flash success message and redirect to the homepage
flash("Sold successfully!")
return redirect("/")
I was having trouble with trivia problems javascript part and after a while I saw the staffs solutions which they have provided and implemented one of them, does this also go against academic dishonesty as they have provided them to be easily accessible?. From what I could understand it was provided to help students as javascript was only glanced over in the last few minutes of the lecture.
so my cs50p certificate is awarded to "Moomin Javeed" which is my name but at the time i didn't realize that on my id and documents the spelling is different its "mumin" will cause any problems in the future, if so what should I do
my code space isn't opening it stuck on the "setting up your codespace" page
Update pop-up was coming from many days so finally updated it. Then then it asked to rebuild it. I clicked rebuild and it was stucked at almost 50% for like 30 minutes. So I closed the tab. Then when i again login i stupidly login with vs code desktop and then this happened. Please help me to get it back to original. I can't use any cs50 commands here, not even check50 or submit50
Hello, I have made the video for the final project of CS50x and instead of displaying name, city/country name I have mentioned it in the video with the voiceover so is it okay to submit it or will it be rejected because this is in the step 1 of submission:
"Create a short video (that’s no more than 3 minutes in length) in which you present your project to the world. Your video must begin with an opening section that displays:
I have seen many videos on CS50's gallery of final project, there was no display of the name but they had said their name and country in the voice over. What should I do?
Should i move to cs50x 2024 fall edistion? if yes by progress will be moved as well right?