#Code Help

47 messages · Page 1 of 1 (latest)

weak pineBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

bold path
#

What do you mean by triggering detectors?

#

I don’t understand what you mean

#

Is the code triggering plagiarism detection?

#

Well, did you write it yourself?

#

I don’t think that is something that anyone can do better than you, tbh

#

Since they don’t know what the detection system looks for

burnt glade
#
  for (int i = 0; i < n; ++i) {
    if (shortestDist[i] < distTo[i]) {
      return false;
    }
  }

🤔
isn't this a bit pointless as you just initialized them all to std::numeric_limits<int>::max()

bold path
#

And it is kida iffy in regards to rule 5

burnt glade
#

shortestDist[0] = 0; this is the only value that isn't the max value

bold path
#

!cheating

weak pineBOT
#
Slacking, Herald of Monke
We do not help with anything pertaining to cheating/hacking/malware.

Aside from ethics and simply not caring for helping script kiddies, this content violates Discord's terms of service and we do not tolerate it.

bold path
#

Wait no

#

Thats not the one

burnt glade
#

well honestly I wouldn't say this is persay against rule 5

#

they did the work, they are just asking how to improve it

bold path
#

Sorry, my bad

burnt glade
#

honestly though, looking at this it's for the most part similar to what I would have written

bold path
#

Some style tips I can give though 🙂

burnt glade
#

like honestly nothing in this code at first glance jumps out to me as a huge issue

burnt glade
bold path
#

I would just remove n and use G.size()

burnt glade
#

sure, but shortestdist[i] is never going to be less then distTo[i]

#

unless it's index 0

bold path
#

You can use a structured binding for u and v

burnt glade
#

yeah that would be significantly better ^

#
  int n = G.size();
  std::vector<int> shortestDist(n, std::numeric_limits<int>::max());
  shortestDist[0] = 0;

also this might potentially crash for empty graphs 🤔

bold path
#

That would look like auto [u, v] = edge;

burnt glade
#

I think allocating a vector with size 0 is oaky but writing to it is a bit iffy

bold path
#

In general it’s poor style to shorten names (like shortestDist instead of shortestDistance)

burnt glade
#

wait but isn't this basically the same?

bold path
#

The code would be clearer if you made u a reference variable to shortestDist[edge.first] and w to a similar thing

#

But that might be just me thinkythonk

burnt glade
#

but that code you linked is the exact same 🤔
mine wasn't a correction just pointing out issues in your code

#

the exact same :D

#

now this one:

  for (int i = 0; i < numVertices; ++i) {
    if (shortestDist[i] < distTo[i]) {
      return false;  
    }
  }

makes significantly more sense

bold path
#

I was thinking that you could simplify the if statement by putting shortestDist[u] into a variable and doing the same thing for the right hand side

auto x = shortestDist[v] + w;
        if (shortestDist[u] > x) {
          shortestDist[u] = x;
        }
}```
#

Like this

#

And similar for u

#

It’s absolutely debatable whether that is an improvement

#

But I think it looks good uwu02

bold path
weak pineBOT
#

@vital turtle Has your question been resolved? If so, run !solved :)

burnt glade
#

sorry, I am working atm don't have to time to debug stuff like that sadly