4
votes
Accepted
PSET3 Tideman: Lock_Pairs Help
This is one of those times when I would recommend starting over. Try and break it down in terms of what you need your function to do, and build some pseudocode first. Some pointers:
First, recursion ...
4
votes
pset3, tideman, cs50 2020
add_pairs should increment pair_count.
sort_pairs would access an element beyond the array length. If you have pair_count elements, you have pair_count-1 neighbour comparisons per round, one less ...
4
votes
Accepted
Pset3: Tideman sort_pairs doesn't work?
preferences[pairs[i].winner][pairs[i].loser] > preferences[pairs[i+1].winner][pairs[i+1].loser]
This condition swaps the elements in ascending order while check50 checks for the pairs array for ...
3
votes
Accepted
Failing add_pairs function check50
I solved it after few hours. Damn.. Silly me.. I just had to remove the two break;s
void add_pairs(void)
{
// TODO
// Preferences integers of stringed candidates
// Candidates string
/...
3
votes
Accepted
Program and debug50 different results
Declaring the array here int matrix[candidate_count]; allocates the memory for it. But it does not initialize the contents. At the end of the for loop, there is a good chance that matrix[m] has not ...
3
votes
lock_pairs skips final pair if it creates cycle lock_pairs did not correctly lock all non-cyclical pairs
Instead of doing if(cycle[i]) do if(cycle(pairs[i].winner)). It should fix your problem because you are just calling a random iterator instead of the index of your respective candidate node.
Also, ...
3
votes
CS50 Pset3 - Tideman - I passed all the checks except for "lock_pairs skips final pair if it creates cycle". What am I doing wrong!
The problem likely originates in your second for loop, where you return check_cycle(j, w) if the condition is true (meaning that there is an edge from the loser to another candidate), and you proceed ...
2
votes
How do I implement lock_pair function correctly in Tideman?
pair[i].winner may be equal to pair[j].loser in many cases where pair[i].winner is not the end element in the chain. Consider voting of three candidates A, B, C where sorted pairs as follows: 1. B->C, ...
2
votes
Accepted
Tideman sort_pairs function
I don't know for a fact because I don't know how the check50 testing works, but I'd bet it's because of that extra strength property. Your program works all together, but the individual functions don'...
2
votes
pset3, vote(); direct comparison failing but strcmp() working?
Review the week 3 lecture starting at the 40 minute mark. From the transcript
And it turns out, for reasons we'll explore in more detail next week, it is not sufficient to do what we did before and ...
2
votes
pset3 tideman lock_pairs: why does "lock_pairs locks all pairs when no cycles" fail?
Being the loser of an already locked pair is not necessarily sufficient to create a cycle. If A beats B, and B beats C, there is no cycle, but your algorithm will not lock in B -> C if A -> B is ...
2
votes
Accepted
p_set3 why does the int main clear the graph of locked in pairs?
Interesting. I am working on the Tideman problem now and didn't notice this block until I read your question. Let's ignore the comment that states "clear graph..." and focus only on what the code is ...
1
vote
Tideman - "lock_pairs skips final pair if it creates cycle" - Almost there!
Ok, I got the solution.
I changed this code:
return check_cycle(loser, i, winCycle, loseCycle);
to
bool check = check_cycle(loser, i, winCycle, loseCycle);
if (check)
return true;
1
vote
Accepted
How to swap elements in "struct" data type?
It's not really clear what you mean by "swapping elements". I can't see why you'd change one element in a struct, but I can see how you might want to swap entire structs.
Say that you have ...
1
vote
Accepted
PSET3 Tideman - What to do with the lock_pairs function?
Specification says that, The function should create the locked graph, adding all edges in decreasing order of victory strength so long as the edge would not create a cycle.
How are cycles created? Let'...
1
vote
Passing arrays into function in tideman
ranks[] means an array of values that has been named ranks; from the declaration, we can tell that the values will all be integers. Any time you see a name followed by square brackets in C-based ...
1
vote
Accepted
Can't determine the problem with my tideman program - check50 fails at lock_pairs function, says I didn't correctly lock all non-cyclical pairs
Thanks to u/yeahIProgram on reddit for this answer:
If you look at the second if statement in my cycleCheck function, it first asks whether the current loser passed to the function is the winner of ...
1
vote
Accepted
pset 3 tideman print winner does not exist despite being declared
Have you compiled the program locally? The compiler should complain about this strlen(champions) because champions is declared an int array here int champions[pair_count]
1
vote
Accepted
PSET 3 - Tideman: Lock Pairs Function
The logic of find_source won't really achieve the objective.
For each candidate, if no one beats that candidate, it will return false without checking subsequent candidates. However, pairs are locked ...
1
vote
Accepted
Tideman - :( lock_pairs skips final pair if it creates cycle
The problem is subtle and just a small error in execution logic:
for (int i = 0; i < candidate_count; i++)
{
if(locked[thisloser][i] == true)
{
return check_cycle(i, original_winner)...
1
vote
Accepted
Tideman: invalid operands to binary expression ('void' > and 'int')
Have a look at your function prototype declared at the top of the file, and compare it to the function declaration in the body of the code.
Remember that when the compiler reaches that line in the ...
1
vote
Accepted
Segmentation fault tideman swap function
If anyone else find this thread and have the same problem, I'll post the code after I solved it:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
// Max number of candidates
...
1
vote
pset3 Tideman: checking for cycles
I found it unnecessary to check multiple branches to the same node the way I executed my lock cycles function. I was very surprised by this. Whether this is related to the fact the graph does not have ...
1
vote
Accepted
Logical flaw in Problem Set 3 - Tideman?
I have had this exact same problem, but managed to resolve it tonight. If this is the only error you are getting, your code is fundamentally correct (as not locking middle pairs would be the greatest ...
1
vote
Accepted
sort_pairs function not working as per check50
I think you're trying to use bubble sort, since you're swapping pairs[i] and pairs[j] if pairs[j] is stronger than pairs[i]. However, bubble sort always swaps adjacent elements, and i and j aren't ...
1
vote
Accepted
What's in the bool function parenthesis?
No such thing as a silly question. It just means that you haven't learned it yet. That's all. ;-)
This is a function "signature". It defines what is expected to be passed to the function. int rank ...
1
vote
Accepted
Pset3: Tideman - Sort_pairs function
check50 doesn't care about how you implemented add_pairs when it's testing sort_pairs, so it doesn't initialize the winsize property. You'll need to remove that property, and access it in sort_pairs. ...
1
vote
Accepted
Tideman, my tests work but check50 says there is an error
Your old code was going through the first n pairs, where n is the number of candidates, then checking if one of the winners of those pairs is the total winner. You can't assume that with n candidates, ...
1
vote
PSET3 -Tideman - Locking Pairs
I don't exactly understand your logic, I found something that feels somewhat simpler in an answer on the new cs50 ed platform. The approach is: For a cycle to appear when you lock a new edge A->B, ...
1
vote
Accepted
CS50x 2020 Problem Set 3 Tideman
Clearly bubblesort algorithm has been used, but in the 5th line:
preferences[pairs[i].winner][pairs[i].loser] > preferences[pairs[i + 1].loser][pairs[i + 1].winner]
The basic functionality of ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
tideman × 70pset3 × 53
cs50x × 18
c × 9
recursion × 5
pset3-tideman × 5
sort-pairs × 4
lock-pairs × 4
error × 3
sort × 3
print-winner × 3
lock × 3
pairs × 3
vote × 3
debug50 × 2
sorting × 2
boolean × 2
bash × 2
segmentation-fault × 1
cs50-ide × 1
function × 1
ide × 1
bubble-sort × 1
printf × 1
problem × 1