3 votes
Accepted

What's the most efficient prime-finding algorithm? (Week 1 Practice Problems)

You can likely google it to find out. But the first thing that comes to mind is to lower the high limit of numbers to check. Simply put, if you're checking whether N is a prime, you need only see if ...
Cliff B's user avatar
  • 68.7k
2 votes
Accepted

Do While loop not executing for pset3

Right before bool sorted = false;, you have return true;. You give a return value before anything else happens, so your function does exactly that: it returns that value and stops executing any ...
Peter's user avatar
  • 1,412
2 votes
Accepted

Can anyone explain that attendence algoritm of week 0 lecture?

Following would be the steps assuming 8 students are in the room 1. Each of them would have the number 1 in their mind and 8 of them would be standing 2. You add the number in your pair's mind (in ...
Chrystz's user avatar
  • 36
1 vote
Accepted

PS2 Caesar Algorithm

The only time this if (ptxt[i] >= 'Z' && isupper(ptxt[i])) will evaluate to true is when ptxt[i] is 'Z'. There is no other (upper case) letter that can be both. (Similarly this else if (...
DinoCoderSaurus's user avatar
1 vote

Why are algorithms mentioned in week 2

Bigger picture: In programming, there are certain tasks that appear over and over in some form or another. Sorting data is one of them. Linked lists are another. These tasks have been analyzed ...
Cliff B's user avatar
  • 68.7k
1 vote
Accepted

Iterative vs Recursive

In the problems that you will find in cs50, you will not find any difference in speed especially in C, as you well say the recursive solution requires more memory usage. We simply use a recursive ...
MARS's user avatar
  • 5,169
1 vote

pset 1 credit.c invalid cards are valid by cs50

What about this 5105105105105100? 1*2 + 5*2 + 0*2 + 1*2 + 5*2 + 0*2 + 1*2 + 0*2 2 + 10 + 0 + 2 + 10 + 0 + 2 + 0 2 + 1 + 0 + 2 + 1 + 0 + 0 + 2 + 0 = 8 8 + 5 + 0 + 1 + 5 + 0 + 1 + 5 + 0 = 25 The ...
imdadable's user avatar
1 vote
Accepted

pset 1 credit.c invalid cards are valid by cs50

371449635398431 is a valid AMEX card. From this post: 3 7 1 4 4 9 6 3 5 3 9 8 4 3 1 Okay, let’s multiply each of the underlined bold digits by 2 7*2 + 4*2 + 9*2 + 3*2 + 3*2 + 8*2 + 3*...
DinoCoderSaurus's user avatar
1 vote

pset 1 credit.c invalid cards are valid by cs50

Where you got 107, I did the maths without calculator, and got to 90. Keep in mind that the digits to double start with the second to last digit (so first digit could be regular or doubled), and that ...
Blauelf's user avatar
  • 20.9k

Only top scored, non community-wiki answers of a minimum length are eligible