/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
I see that the deadline for the problem sets are 1st Jnauary 2025 but what happens after that?
Hello!
I’m currently working on an open-source project called QuikHit, and I’m looking for feedback, suggestions, and potential contributors from the community. QuikHit is a platform designed to help live streamers monetize their streams by offering quick, dynamic ad spots that businesses can easily purchase. The core idea is to make it effortless for streamers to manage ad space, enabling smaller businesses to place targeted ads on platforms like Twitch.
About the Project:
• Rough Codebase: The current codebase is still rough and in its early stages, but it includes both backend and frontend components.
• Tech Stack: We’re using Node.js for the backend and React.js for the frontend. There’s also integration with the Twitch API for real-time bidding and ad placement.
Features So Far: • Basic Ad Auction System: Implemented an initial version of an auction-based ad placement system. • OBS Plugin Integration: We’ve started building an OBS plugin to make it easy for streamers to display ads during live streams. • Payment System: We have basic payment functionality for managing transactions and commissions for ads sold.
What We’re Looking For:
• Feedback on Code and Architecture: This is very much a work in progress, and I’d love to get insights on the architecture, scalability, or even just best coding practices to make this better.
• Contributors: We’re especially looking for developers interested in Node.js, React, real-time WebSockets, and API integration. If you have experience working with Twitch, YouTube, or OBS plugins, your insights would be incredibly valuable!
• New Features and Suggestions: If you have ideas on features that could make the platform better, we’re very open to expanding the project to solve real problems for streamers and businesses alike.
Why Contribute?: • We’re aiming to make QuikHit a scalable, industry-changing platform that could potentially be used by many streamers to enhance their income and provide targeted ad opportunities for businesses.
How to Get Involved:
• You can check out the GitHub repository here: (https://github.com/kylemac21188/QuikHit-MVP)
• Feel free to open an issue if you spot something, or grab one of the “good first issues” if you want to contribute.
• If you just want to chat or learn more, you can leave a comment here, or reach out via GitHub.
Roadmap:
We have a lot of plans for QuikHit: 1. Enhance the auction system to support more complex bidding strategies. 2. Real-time metrics and analytics for both streamers and advertisers. 3. Improve OBS integration so ads can be dynamically placed based on real-time conditions. 4. Build a comprehensive dashboard for streamers to manage their campaigns, view statistics, and optimize their ad revenue.
Thanks in advance for taking the time to check it out, and I look forward to any insights you all hav
:( minimax blocks immediate three-in-a-row threat
expected "(2, 1)", not "(0, 0)"
:( minimax finds only winning move
expected "(2, 0)", not "(0, 1)"
def Max_Value(board):
v = -math.inf
if terminal(board):
return utility(board)
for action in actions(board):
v = max(v, Min_Value(result(board, action)))
return v
def Min_Value(board):
v = math.inf
if terminal(board):
return utility(board)
for action in actions(board):
v = min(v, Max_Value(result(board, action)))
return v
def minimax(board):
"""
Returns the optimal action for the current player on the board.
"""
if terminal(board) == True:
return None
elif player(board) == X:
moves=[]
for action in actions(board):
moves.append([Min_Value(result(board, action)), action])
return sorted(moves, key=lambda x: x[0], reverse=True)[0][1]
elif player(board) == O:
moves=[]
for action in actions(board):
moves.append([Max_Value(result(board, action)), action])
return sorted(moves, key=lambda x: x[0])[0][1]
this my code block for the minimax function.
could anyone help tell me where i went wrong?
def player(board):
"""
Returns player who has the next turn on a board.
"""
xcount = 0
ocount = 0
for i in board:
for j in i:
if j == X:
xcount +=1
elif j == O:
ocount +=1
if xcount == 0 and ocount == 0:
return X
if xcount > ocount:
return O
else:
return X
def actions(board):
"""
Returns set of all possible actions (i, j) available on the board.
"""
actions = set()
for i_index, i in enumerate(board):
for j_index, j in enumerate(i):
if j == EMPTY:
actions.add((i_index, j_index))
return actions
def result(board, action):
"""
Returns the board that results from making move (i, j) on the board.
"""
new_board = copy.deepcopy(board)
row, col = action
if action not in actions(board):
raise Exception("not a valid action")
new_board[row][col] = player(board)
return new_board
def winner(board):
"""
Returns the winner of the game, if there is one.
"""
for row in board:
if row[0]==row[1]==row[2]!=EMPTY:
return row[0]
i, j, k = board
for x in range(2):
if i[x]==j[x]==k[x]!=EMPTY:
return i[x]
if i[0]==j[1]==k[2]!=EMPTY or i[2]==j[1]==k[0]!=EMPTY:
return j[1]
else:
return None
def terminal(board):
"""
Returns True if game is over, False otherwise.
"""
if winner(board) == X or winner(board) == O:
return True
count=0
for i in board:
for j in i:
if j == EMPTY:
count +=1
if count == 0:
return True
else:
return False
def utility(board):
"""
Returns 1 if X has won the game, -1 if O has won, 0 otherwise.
"""
if winner(board) == X:
return 1
if winner(board) == O:
return -1
else:
return 0
This the code for the rest of my functions if case yall there's something i missed out here
Got a bit creative for this problem set on my own and thought it was funny to do that and at the same time implement 2 ideas i learned from the lecture in 1
Hi everyone! I want to actually my final project live online so other people can register and use it, any tutorials/videos/books on how to make this possible? I built a Django WebApp using Codespaces, It's now working correctly locally but want to deploy it online.
Thanks in advance!
If anyone knows her plzz dm me
Speller doesn't exit after it is executed. If it can't load a file speller calls unload and this happens again. There is something wrong with the unload function but I can't figure out what. Any suggestions would be appreciated.
For my final project I made a Times Tables Worksheet Generator. It takes user input and puts a table with the specified number of questions onto a background I made in Canva.
Long story short, there's this problem in Week 7 that has been bugged me for 3 days now, it haunts me in my dream. I can just look for solutions online but should I do that? Is there any other more effective way?
I’m currently doing CS50x and i want to know if i should do other courses as well like DSA, side by side. I just want to have a better understanding of Computer Science. And if any of you know any websites for these types of courses, I’d appreciate.
Whenever I try to run my code I get a segmentation fault at n->next = table[index]->next;
My table size is 26 cubed.
unsigned int hash(const char *word)
{
// TODO: Improve this hash function
int len = strlen(word);
if (len >= 3)
{
return (word[0] - 96) * (word[1] - 96) * (word[2] - 96);
}
else if (len == 2)
{
return (word[0] - 96) * (word[1] - 96) * (word[1] - 96);
}
else
{
return (word[0] - 96) * 3;
}
}
// Loads dictionary into memory, returning true if successful, else false
bool load(const char *dictionary)
{
// TODO
FILE *source = fopen(dictionary, "r");
if (source == NULL)
{
return false;
}
char word[LENGTH + 1];
while (fscanf(source, "%s", word) != EOF)
{
fscanf(source, "%s", word);
node *n = malloc(sizeof(node));
if (n == NULL)
{
return false;
}
strcpy(n->word, word);
int index = hash(n->word);
n->next = table[index]->next;
table[index] = n;
}
fclose(source);
return true;
}
I'm sure there's other issues with this code but I'm not really sure. Any advice would be appreciated. Thanks!
Hi all, I started CS50P earlier this year as I've always wanted to learn a programming language and, based on checking out various recommendations, decided that this is a better course for me to start with than CS50x.
Well, having gotten to Week 8, it's been the most fun educational experience of my life and I'm deciding what to do next to strengthen the foundation I've built (I've also worked through Crash Course in Python parallel to taking CS50P).
The obvious choice is to take CS50x next. However, I've gotten the itch to complete projects from scratch and have taken an interest in web development. Would I be okay setting aside CS50x for now and jumping into CS50W first? It seems to be a bit more practical and I'm excited at the opportunity to complete several projects by the end of the course. I absolutely want to take CS50x after CS50W to strengthen my overall understanding of computer science, but after the focused experience of CS50P, I'm afraid it may feel like too much of a detour after getting fired up about Python and also web development.
Any thoughts or advice for me? Would I find CS50W too challenging or confusing without first taking CS50x?
I have been trying to figure this shit out for two days. Can someone smarter then me explain how I am fu**ing up?
My code:
import sys
import csv
def main():
if len(sys.argv) > 3:
sys.exit("Too many command-line arguments")
elif len(sys.argv) < 3:
sys.exit("Too few command-line arguments")
input_file = sys.argv[1]
output_file = sys.argv[2]
if not input_file.endswith("csv"):
sys.exit(f"{input_file} is not a valid csv file")
if not output_file.endswith("csv"):
sys.exit(f"{output_file} is not a valid csv file")
scourgify(input_file, output_file)
def scourgify(input_file, output_file):
try:
with open(input_file, "r") as file, open(
output_file, "w", newline=""
) as new_file:
reader = csv.DictReader(
file,
)
fieldnames = [
"first",
"last",
"house",
]
writer = csv.DictWriter(new_file, fieldnames=fieldnames)
writer.writeheader()
for row in reader:
last_name, first_name = row["name"].split(",")
new_row = {
"first": first_name,
"last": last_name,
"house": row["house"],
}
writer.writerow(new_row)
except FileNotFoundError:
sys.exit(f"Could not read {sys.argv[1]}")
if __name__ == "__main__":
main()
TThe first rows of the input file "before.csv":
The first rows of the generated output file "after.csv":
My results:
Hi folks i've spent quite while on tideman and am a little frustrated that my code doesnt seem to get pass all the check50 boxes (only one left :///)!
could any kind soul give me a hint as to why my lock pairs function does not work? i even tried debugging with and my final pair seems to be working fine. thank you so much!
disclaimer: my code may be quite lengthy and it definitely isnt the best way but still i'm not sure why it doesnt work ://
void lock_pairs(void)
{
for (int i = 0; i < candidate_count; i++)
{
int x = 0; // resets x to zero for each pair. this is passed onto the check function
locked[pairs[i].winner][pairs[i].loser] = true;
int checksum = check(pairs[i].loser, x); //function to check for cycles is defined down below. it takes two inputs
if (checksum == candidate_count)
{
locked[pairs[i].winner][pairs[i].loser] = false;
}
}
return;
}
int check(int n, int x)
{
if (x == candidate_count )
{ // there is a loop if x is = candidate count (x candidates means max x edges for a loop )
return candidate_count ;
}
for (int j = 0; j < candidate_count; j++)
{
if (locked[n][j] == true)
{
//checks if there is a subsequent edge
int tempvar = j;
x++;
return check(tempvar, x);
}
}
return -1; //returns back to lock pair function
}
Pls recommend it ( if possible something in Java)
:)
outdated.py
exists
:) input of 9/8/1636 outputs 1636-09-08
:) input of September 8, 1636 outputs 1636-09-08
:) input of 10/9/1701 outputs 1701-10-09
:) input of October 9, 1701 outputs 1701-10-09
:) input of " 9/8/1636 " outputs 1636-09-08
:) input of 23/6/1912 results in reprompt
:( input of 10 December, 1815 results in reprompt
expected program to reject input, but it did not
:( input of October/9/1701 results in reprompt
expected program to reject input, but it did not
:) input of 1/50/2000 results in reprompt
:) input of December 80, 1980 results in reprompt
:( input of September 8 1636 results in reprompt
expected program to reject input, but it did not
Can someone please help me understand what the checker expects when it says "repromt" and when it says "expected program to reject input".
From what I understand "reprompt" is the program that we have made needs to ask the user for input again ( in this case it would ask "Date: ") and "expected program to reject input" is the prorgram need to stop and no further input will be taken (meaning the user needs to rerun the program to input something again)
So, I thought the last part would be easy after lock_pairs, but I am getting the "print_winner for ties" error. Below is my code, and it checks the locked[ i ][ j ] matrix, to find anyone that never loses. So during the loop, if any i "cell" from column J is true, it assumes that candidate J is not the source/winner, and it breaks out of the loop, to check on J+1.
My code will always print every candidate[ j ] that has no arrow pointing to it.
But check50 does not accept this. Can someone help me to find the fault in my logic?
Many thanks!
void print_winner(void)
{
for (int j = 0; j < candidate_count; j++)
{
for (int i = 0; i < candidate_count; i++)
{
if (locked[i][j]) // Checks the next j because it found a true on row i (i.e. loser)
{
break;
}
if (i == candidate_count - 1) // Reached the end of column j and every i is false
// therefore j must be the source!
{
printf("%s\n", candidates[j]);
}
}
}
}
As I said Above I don't know anything about programming, I made some research and found that CS50 is a good way of starting programming Where should I start this course like from EdX or CS50 course website and Do I need any prerequisites before starting course??
This is all the work and notes I've done so far. I thought I had a match with the phone call record, but no... What am I missing here? It's driving me nuts....
-- Keep a log of any SQL queries you execute as you solve the mystery.
-- sqlite3 fiftyville.db (To load database)
-- .tables (To view all tables)
-- SELECT * FROM crime_scene_reports WHERE day = 28 AND month = 7 AND year = 2023;
--(Crime Scene Reports for specific date)
-- SELECT * FROM interviews WHERE day = 28 AND month = 7 AND year - 2023;
--(All interviews for specific date)
-- SELECT * FROM bakery_security_logs;
--(Get security logs for the bakery)
-- SELECT * FROM bakery_security_logs
-- WHERE day = 28 AND month = 7 AND year = 2023;
--(Select bakery security logs on specific date)
-- SELECT * FROM atm_transactions
-- WHERE atm_location = 'Leggett Street'
-- AND day = 28 AND month = 7 AND year = 2023;
--(Get ATM transactions from specific atm location on certain day)
-- SELECT * FROM phone_calls
-- WHERE day = 28 AND month = 7 AND year = 2023 AND duration <= 60;
--(Get phone calls from a certain day with a certain duration)
-- SELECT * FROM flights
-- WHERE day = 29 AND month = 7 AND year = 2023;
--(List all flights for a certain day)
-- SELECT * FROM airports;
--(List all airports)
-- SELECT * from passengers WHERE flight_id = '36';
--(List all passengers and info for a specific flight)
-- SELECT * FROM people
-- WHERE passport_number IN ('', '', ...)
--(Select people with matching passport numbers)
Notes:
Crime Scene Reports:
Report 295
Theft of CS50 duck at Humphrey Street bakery
7/28/2023 at 10:15am
3 Witnesses present
Interviews:
Ruth: Sometime within 10 minutes of the theft, saw thief get into a car in the bakery parking lot and drive away. Check security footage for car that left during that time.
Eugene: Earlier in the day, saw thief withdrawing money from an ATM on Leggett Street.
Raymond: As the thief was leaving the bakery, they called someone and spoke with someone for less than a minute. The thief said they were planning to take the earliest flight out of Fiftyville tomorrow (July 29, 2023). The thief then asked the other person on the phone to purchase the flight ticket.
Bakery Security Camera Logs (10:15-10:25)
260 | 2023 | 7 | 28 | 10 | 16 | exit | 5P2BI95 |
| 261 | 2023 | 7 | 28 | 10 | 18 | exit | 94KL13X | !!!!!!!! – Bruce
| 262 | 2023 | 7 | 28 | 10 | 18 | exit | 6P58WS2 |
| 263 | 2023 | 7 | 28 | 10 | 19 | exit | 4328GD8 | !!!!!!!!! – Luca
| 264 | 2023 | 7 | 28 | 10 | 20 | exit | G412CB7 | !!!!!!!!! – Sofia
| 265 | 2023 | 7 | 28 | 10 | 21 | exit | L93JTIZ |
| 266 | 2023 | 7 | 28 | 10 | 23 | exit | 322W7JE |
| 267 | 2023 | 7 | 28 | 10 | 23 | exit | 0NTHK55 !!!!!!!!!! – Kelsey
ATM Transaction Records:
id | account_number | year | month | day | atm_location | transaction_type | amount |
+-----+----------------+------+-------+-----+----------------+------------------+--------+
| 246 | 28500762 | 2023 | 7 | 28 | Leggett Street | withdraw | 48 |
| 264 | 28296815 | 2023 | 7 | 28 | Leggett Street | withdraw | 20 |
| 266 | 76054385 | 2023 | 7 | 28 | Leggett Street | withdraw | 60 |
| 267 | 49610011 | 2023 | 7 | 28 | Leggett Street | withdraw | 50 |
| 269 | 16153065 | 2023 | 7 | 28 | Leggett Street | withdraw | 80 |
| 275 | 86363979 | 2023 | 7 | 28 | Leggett Street | deposit | 10 |
| 288 | 25506511 | 2023 | 7 | 28 | Leggett Street | withdraw | 20 |
| 313 | 81061156 | 2023 | 7 | 28 | Leggett Street | withdraw | 30 |
| 336 | 26013199 | 2023 | 7 | 28 | Leggett Street | withdraw | 35
Phone Calls:
id | caller | receiver | year | month | day | duration |
+-----+----------------+----------------+------+-------+-----+----------+
| 221 | (130) 555-0289 | (996) 555-8899 | 2023 | 7 | 28 | 51 |!!!!! C: Sofia
| 224 | (499) 555-9472 | (892) 555-8872 | 2023 | 7 | 28 | 36 | !!!!! C: Kelsey
| 233 | (367) 555-5533 | (375) 555-8161 | 2023 | 7 | 28 | 45 | !!!!! C: Bruce
| 234 | (609) 555-5876 | (389) 555-5198 | 2023 | 7 | 28 | 60 | !!!!!! R: Luca
| 251 | (499) 555-9472 | (717) 555-1342 | 2023 | 7 | 28 | 50 |
| 254 | (286) 555-6063 | (676) 555-6554 | 2023 | 7 | 28 | 43 | !!!!! C: Taylor
| 255 | (770) 555-1861 | (725) 555-3243 | 2023 | 7 | 28 | 49 |
| 261 | (031) 555-6622 | (910) 555-3251 | 2023 | 7 | 28 | 38 |
| 279 | (826) 555-1652 | (066) 555-9701 | 2023 | 7 | 28 | 55 | !!!!! C: Kenny !!!!! R: Doris
| 281 | (338) 555-6650 | (704) 555-2131 | 2023 | 7 | 28 | 54 |
Flight Records:
id | origin_airport_id | destination_airport_id | year | month | day | hour | minute |
+----+-------------------+------------------------+------+-------+-----+------+--------+
| 18 | 8 | 6 | 2023 | 7 | 29 | 16 | 0 |
| 23 | 8 | 11 | 2023 | 7 | 29 | 12 | 15 |
| 36 | 8 | 4 | 2023 | 7 | 29 | 8 | 20 |
| 43 | 8 | 1 | 2023 | 7 | 29 | 9 | 30 |
| 53 | 8 | 9 | 2023 | 7 | 29 | 15 | 20 |
| 36 | 8 | 4 | 2023 | 7 | 29 | 8 | 20 |
Flight Info:
Flight ID: 36
Origin Airport: 8 – Fiftyville
Destination Airport: 4 – LaGuardia, New York City
Passenger Info:
flight_id | passport_number | seat |
+-----------+-----------------+------+
| 36 | 7214083635 | 2A | !!!!!! – Doris
| 36 | 1695452385 | 3B | !!!!!!! -- Sofia
| 36 | 5773159633 | 4A | !!!!!!! – Bruce
| 36 | 1540955065 | 5C | !!!!!! – Edward
| 36 | 8294398571 | 6C | !!!!!! – Kelsey
| 36 | 1988161715 | 6D | !!!!! – Taylor
| 36 | 9878712108 | 7A | !!!!! – Kenny
| 36 | 8496433585 | 7B !!!!!!! – Luca
People who matched with above passport numbers:
id | name | phone_number | passport_number | license_plate |
+--------+--------+----------------+-----------------+---------------+
| 395717 | Kenny | (826) 555-1652 | 9878712108 | 30G67EN | !!!!!!
| 398010 | Sofia | (130) 555-0289 | 1695452385 | G412CB7 | !!!!!!
| 449774 | Taylor | (286) 555-6063 | 1988161715 | 1106N58 | !!!!!
| 467400 | Luca | (389) 555-5198 | 8496433585 | 4328GD8 | !!!!!!!
| 560886 | Kelsey | (499) 555-9472 | 8294398571 | 0NTHK55 | !!!!!!
| 651714 | Edward | (328) 555-1152 | 1540955065 | 130LD9Z | !!!!!!
| 686048 | Bruce | (367) 555-5533 | 5773159633 | 94KL13X | !!!!!!
| 953679 | Doris | (066) 555-9701 | 7214083635 | M51FA04 !!!!!!
Hello!
As the title of this post says, can I use the 'math.h' header file on week 4's problem filter-less? I couldn't understand by the commands if I may or not.
Finally!! It was a lot of work, but so worth it. Thanks to David and all the team at CS50 for this great resource.
This is the second time I've done CS50 as I wanted to learn Python and SQL. Last time round was 9 years ago using PHP. I intend to do the Web path next :)
For all those of you still trying, stick with it and ask for help when you are stuck. Best of luck to you all.
I must admit the Rubber duck AI is such a great addition.
Hello, I have been trying very hard to solve the problems from week 3 onwards to the point where I simply did not attempt any for the last 2 months. They are just so difficult, in terms of problem solving. Will it be a good idea to skip to Python (Week 6) and the remaining ones before coming back to Week 3, 4, 5? Are the problems beyond Week 5 a tad easier? Or should I just start from week 3 again as it will build the base that is necessary to understand the later weeks' material and tackle those problem sets?
I finally did it! I completed CS50X!
Thank you so much to David for the course content and the whole team for this amazing experience.
Please check out my final project and my GitHub.
If anyone has any recommendations on what I should do next I would love to hear it :)
Hi everyone,
I finally passed all the tests for the finance problem. Out of curiosity, how many tables did you all end up using? Initially, I overcomplicated things by creating three tables: users
, transactions
, and portfolios
. Eventually, I realized I didn’t actually need the portfolios
table and could get by without JOINing tables in my SQLite queries.
That said, it got me thinking about how this might work in the real world. Would developers really query an endlessly growing transactions
table, or would they handle it differently?
Looking forward to hearing your thoughts!
Hi all,
I'm doing CS50 Python Week 1, and I am struggling with Check50 for the problem set "Meal Time". Check50 is telling me that the convert() function outputs "Error" instead of 7.5. But I have printed the converted time after generating it and I am 100% it returns 7.5.
The program is running correctly on all checks suggested by CS50 manually.
What am I missing? Thanks for your help!
Here is the CS50 error message:
Here is my code:
def main():
hours, minutes = input("What time is it? ").split(":")
time_in_hrs = convert(hours, minutes)
if 7.0 <= time_in_hrs <= 8.0:
print("breakfast time")
elif 12.0 <= time_in_hrs <= 13.0:
print("lunch time")
elif 18.0 <= time_in_hrs <= 19.0:
print("dinner time")
def convert(hours, minutes):
convert_hours = int(hours)
convert_minutes = int(minutes)/60
convert_time = float(convert_hours + convert_minutes)
return convert_time
if __name__ == "__main__":
main()