• maegul (he/they)
    link
    fedilink
    English
    7
    edit-2
    1 year ago

    Otherwise, realistically, I’m prob the worst of all worlds … the procrastinator waiting/hoping to be the pair programmer that has hopefully remembered to just be the thief.

  • lwhjp
    link
    fedilink
    751 year ago

    TDD

    const max12 = (x, y) => {
        if (x === 1 && y === 2) {
            return 2;
        } else if (x === 7 && y === 4) {
            return 7;
        } else {
            return x;
        }
    };
    
  • @[email protected]
    link
    fedilink
    English
    301 year ago

    Mathematician 2 kinda blew my mind, kinda obvious, just can’t believe I was never taught or thought about it.

  • @[email protected]
    link
    fedilink
    191 year ago
    #define max(x,y) ( { __auto_type __x = (x); __auto_type __y = (y); __x > __y ? __x : __y; })
    

    GNU C. Also works with Clang. Avoids evaluating the arguments multiple times. The optimizer will convert the branch into a conditional move, if it doesn’t I’d replace the ternary with the “bit hacker 2” version.

  • GTG3000
    link
    fedilink
    Русский
    31 year ago

    Why use const max = (x, y) => x > y ? x : y instead of function max(x, y) { return x > y ? x : y } ?

  • dinckel
    link
    fedilink
    21 year ago

    2, but I’m incredibly embarrassed to say that I’ve had to do 9 before

      • dinckel
        link
        fedilink
        21 year ago

        That was precisely the reason. I prefer strongly typed languages languages, so it just felt gross to write that

  • @[email protected]
    link
    fedilink
    8
    edit-2
    1 year ago

    If thief is actually an option, then thief.

    Otherwise probably procreator or engineer 😅😬

    Edit: errrrr that was supposed to say “procrastinator” 😬dyac

    • @[email protected]
      link
      fedilink
      1
      edit-2
      1 year ago

      so 0.3 ~= 1-ln(2)=max(1-ln(2),1-ln(2)) = floor(ln(2*e^(1-ln(2)))) = floor(ln(2)+(1-ln(2))) = 1 ?

      That would bee engeneer 2, not Mathematician3 xD.

      Just out of curiostity, what was you Idea behind that?

      • @[email protected]
        link
        fedilink
        3
        edit-2
        1 year ago

        Guess only work with integers, specially for the floor function that is going to give you an integer at the end everytime.

        Not my idea, learned it somewhere while doing college in an statistics class. The idea is that the exponential function grow really fast, so small difference on variables become extreme difference on the exponential, then the log function reverse the exponential, but because it grew more for the biggest variable it reverts to the max variable making the other variables the decimal part (this is why you need the floor function). I think is cool because works for any number of variables, unlike mathematician 2 who only work for 2 variables (maybe it can be generalized for more variables but I don’t think can be done).

        For a min fuction it can be use ceiling(-ln(e^-x + e^-y))

        • @[email protected]
          link
          fedilink
          2
          edit-2
          1 year ago

          to be fair it does seem to work for any two numbers where one is >1. As lim x,y–> inf ln(ex+ey) <= lim x,y --> inf ln(2 e^(max(x,y))) = max(x,y) + ln(2).

          I think is cool because works for any number of variables

          using the same proof as before we can see that: lim,x_i -->inf ln(sum_i/in I} e^(x_i)) <= ln(I|) +max{x_i | i /in I.

          So it would only work for at most [base of your log, so e<3 for ln] variables.

          • @[email protected]
            link
            fedilink
            21 year ago

            I don’t have a mathematical proof, but doing some experimental tests on excel, using multiple (more than 3) numers and using negative numbers (including only negative numbers) it works perfectly every time.

            • @[email protected]
              link
              fedilink
              2
              edit-2
              1 year ago

              Try (100,100,100,100,100,101) or 50 ones and a two, should result in 102 and 4 as a max respectively. I tried using less numbers, but the less numbers you use, the higher the values (to be exact less off a deviation(%-difference) between the values, resulting in higher numbers) have to be and wolframAlpha does not like 10^100 values so I stopped trying.

            • @[email protected]
              link
              fedilink
              2
              edit-2
              1 year ago

              thanks for looking it up:).

              I do think the upper bound on that page is wrong thought. Incedentally in the article itself only the lower bound is prooven, but in its sources this paper prooves what I did in my comment before as well:

              for the upper bound it has max +log(n) . (Section 2, eq 4) This lets us construct an example (see reply to your other comment) to disproove the notion about beeing able to calculate the max for many integers.

  • @[email protected]
    link
    fedilink
    121 year ago

    Engineer I guess… Thief is the objectively better enterprise programmer option but I don’t know why I always forget about it and just write a ternary ¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯

    • @[email protected]
      link
      fedilink
      101 year ago

      JS instills distrust. Rely on built-in sort? It’s alphanumeric. Rely on built-in reverse? It modifies your array. Copy an array? No you didn’t.

      Yeah no kidding we bang out a kata in a dozen characters. I don’t even believe in order of operations at this point. I’ve been routinely betrayed.

  • @[email protected]
    link
    fedilink
    111 year ago

    Reminded of how truly little I know about programming despite the time have spent doing it

    Ugh. I’ll never be any good.

    • TheHarpyEagle
      link
      fedilink
      111 year ago

      Listen, in industry programming (and for personal projects if you want to get them done), the thief is the way to go. By all means, challenge yourself to understand each of these functions, but 99% of day to day development will not look like this.

    • @[email protected]
      link
      fedilink
      61 year ago

      How much time have you spent doing it? What part didn’t you understand? If it’s the bit shifting stuff, don’t worry about it - hardly anyone actually knows how that works unless they look it up.

      • @[email protected]
        link
        fedilink
        31 year ago

        About a year with varying levels of commitment and intensity.

        I kind of just threw myself into the deep end. Which was a rewarding but frustrating experience. My first project was one hot encoding 400gb of reddit porn to try and teach stylegan3 how to make porn. And then turning the function on in stylegan3. And then there was validating the images and ditching the ones that erroted. Resizing the whole datasets. Using ffmpeg to extract stills from the gifs and mp3s

        I found stable diffusion existed like 5 days into actually training it which was bitter sweet. I mean. No way it would have produced actual porn but I was really looking forward to the horror.

        I taught myself as I went along which is a great way to learn but it’s super disheartening when I see the math that’s second nature to anyone whose studied this stuff academically… I don’t like math. In fact I hate it, and no matter how skilled (or not) a coder I become I’ll never learn calculus sometimes makes it all feel like a fools errand.

        • @[email protected]
          link
          fedilink
          21 year ago

          I also hate math, and am jealous of people who are good at it. I get anxiety just doing simple multiplications, and have to look everything up. That said, I’m a senior platform developer, and earn more than anyone else in my family, so like… math helps a lot, but you don’t neeed it to be a real dev. Certainly not to be a hobbyist/hacker, like yourself.