Ad
  • Custom User Avatar

    Don't worry. There is only a little chance to come up with this yourself. Either you know it from somewhere or you don't.

  • Default User Avatar
  • Custom User Avatar

    And a perfect example of ChatGPT answering the prompt correctly and you misreading it. He specifically wrote "I asked ChatGPT to explain this code ... and got exactly what he asked for.

  • Default User Avatar

    is there a reason to not leaving a space? like why cramp them together instead of

    return position + roll /* 2

  • Default User Avatar
  • Custom User Avatar
  • Default User Avatar
  • Default User Avatar

    7 lines is not bad. Honestly I'll defend my 4 line solution as being a better practice because it's more legible to other people, even if it isn't as clever as this one. And this one is clever! I'm not here to be a hater. I just get frustrated when people mistake "shortest" for "best." Imagine if one of your coworkers wrote this code, went on vacation, the code broke, and then you had to debug it. I don't think it would result in great professional cohesion.

  • Default User Avatar

    Totally agree. I love when solutions are short and clever, and if I could FOR THE LIFE OF ME figure out what the heck is going on here, I might use it for personal things. But professionally, your code is going to be passed along to other people. It just is. Being a smirking know-it-all about how you're better at math than everyone else (which is not what I think the person who posted the solution is doing, but certain other people in the vicinity sure are!) is only going to make your coworkers hate you and the work more cumbersome. If the micromilliseconds that a solution like this shaves off actually matter, then that will be part of the stated requirements. Otherwise, it's counterproductive to do something confusing.

    Imagine this: you write some indecipherable code and then go on vacation. Something else in the project changes, causing your code to no longer work*, but no one except you understands what you wrote well enough to debug it. When you get back from vacation, they're not going to think you're a genius. They're going to think you're a jerk. (Which is to say nothing of the probability that you also won't understand it once you haven't looked at it in a while!)

    * I find it really interesting how many people think that "shave off imperceptible amounts of time" is a omnipresent, implicit requirement, but "harden your code against foreseeable weak spots" is a low priority that can be handled later. When they also think that "make it legible to other people" is a low priority, I really have to wonder what it is we're actually even doing here.

    (All that said, the solution is, best I can tell, really clever! There's nothing wrong with someone having created or posted it - the opposite of wrong, that's fantastic! I am about to spend a lot of time on google and probably learn something! It's amazing how the human mind can weave different concepts and understandings together to come up with something really elegant! For the actual purpose of this website - practice - this is a great answer. But you are completely correct that it would not be best practice in a professional setting, and it makes me nuts when people just say "well maybe other people should just know all the things I know!" rather than engaging with practical limitations and basic interpersonal realities.

  • Custom User Avatar

    geniuses admire simplicity

  • Custom User Avatar
  • Default User Avatar

    cool! took me a while to understand tho

  • Default User Avatar
  • Custom User Avatar

    Oh I should have thought of this.
    My inner math teacher is screaming.
    Well played.

  • Default User Avatar

    I see stuff like this and think that maybe this is not for me :*)

  • Loading more items...