You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was solving pset3 of CS50 and got stuck at tideman problem of pset3,
I browsed on internet for some help and came to your solution(which helped me a lot to understand problem)....
While going through your code, I thought validateLock() function of your code might be incorrect( also I might be wrong 😄 ),
you are going through locked array linearly(like 1 row at a time), instead you should search alternatively....
I mean, consider pair (1,2) (2,3) (3,1)
the way you search is is,
first comparing 1 to 1,2,3
then 2 to 1,2,3
then 3 to 1,2,3
instead you should search as
first 1 to 2, then 2 to 3, and lastly 3 to 1
here is the solution that i came up with,
voidvalidateLock(intx, intwinner, intloser)
{
for (inti=0; i<candidate_count; i++)
{
if (lock== false)
{
return;
}
if (locked[x][i] == true)
{
if (x==winner&&i==loser)
{
lock= false;
return;
}
validateLock(i, winner, loser);
}
}
}
voidlock_pairs(void)
{
for (inti=0; i<pair_count; i++)
{
locked[pairs[i].winner][pairs[i].loser] = true;
validateLock(pairs[i].loser, pairs[i].winner, pairs[i].loser);
// if the validateLock function found a cycle we reverse the lockif (!lock)
{
locked[pairs[i].winner][pairs[i].loser] = false;
}
lock= true;
}
}
here i keep referance of staring pair as winner & loser
and start searching from one step ahead....
As I previously said, I might be wrong 😅 ,
btw thanks for posting solution publicly, I helped me a lot....
Hello DeWill here
I was solving pset3 of CS50 and got stuck at tideman problem of pset3,
I browsed on internet for some help and came to your solution(which helped me a lot to understand problem)....
While going through your code, I thought validateLock() function of your code might be incorrect( also I might be wrong 😄 ),
you are going through locked array linearly(like 1 row at a time), instead you should search alternatively....
I mean, consider pair (1,2) (2,3) (3,1)
the way you search is is,
first comparing 1 to 1,2,3
then 2 to 1,2,3
then 3 to 1,2,3
instead you should search as
first 1 to 2, then 2 to 3, and lastly 3 to 1
here is the solution that i came up with,
here i keep referance of staring pair as winner & loser
and start searching from one step ahead....
As I previously said, I might be wrong 😅 ,
btw thanks for posting solution publicly, I helped me a lot....
with regards DeWill
The text was updated successfully, but these errors were encountered: